• Resolved yotamdahan

    (@yotamdahan)


    Hi, From what I’ve checked there is no polylang integration.
    the values of what already has been donated are not equal in all languages.
    How can I solve this?

    The page I need help with: [log in to see the link]

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author flinnn

    (@flinnn)

    The progress bar shows the sales for a single product. If the product is copied and translated into different languages, they are different products internally, because the ID changes. With the next update, I’m adding the feature to insert a collective progress bar for multiple products via shortcode. Would that solve your problem?

    Thread Starter yotamdahan

    (@yotamdahan)

    @flinnn Yes its solve it, but I need a solution for now, you have any idea what can I do?

    Plugin Author flinnn

    (@flinnn)

    If you know some php, it shouldn’t be that hard to customize the calculation. You just have to change the product meta entry with the key “wcdp_total_revenue”.
    Have a look at the following file: https://github.com/jonas-hoebenreich/wc-donation-platform/blob/main/includes/class-wcdp-progress.php
    All the magic happens in the updateTotalRevenueOfProduct() function. You just have to make sure that revenue is overwritten to the value you want.

    Thread Starter yotamdahan

    (@yotamdahan)

    	/**
    	 * Calculate and update the total revenue of a product
    	 * @param $productid
    	 */
    	private function updateTotalRevenueOfProduct($productid) {
    		global $wpdb;
    		$query ="SELECT
                            SUM(ltoim.meta_value) as revenue
                        FROM
                            {$wpdb->prefix}woocommerce_order_itemmeta wcoim
    			        LEFT JOIN
                            {$wpdb->prefix}woocommerce_order_items oi ON wcoim.order_item_id = oi.order_item_id
    			        LEFT JOIN
                            {$wpdb->prefix}posts wpposts ON order_id = wpposts.ID
    			        LEFT JOIN
                            {$wpdb->prefix}woocommerce_order_itemmeta ltoim ON ltoim.order_item_id = oi.order_item_id AND ltoim.meta_key = '_line_total'
    			        WHERE
                            wcoim.meta_key = '_product_id' AND wcoim.meta_value = %d AND wpposts.post_status = 'wc-completed';";
    
    		
    		$translations = pll_get_post_translations($productid);
    		foreach($translations as $item){
    
    			$result = $wpdb->get_row($wpdb->prepare( $query, $item ), ARRAY_A);
    
    			if (!is_null($result) && isset($result['revenue'])) {
    				update_post_meta( $item, 'wcdp_total_revenue', array('revenue' => (float) $result['revenue'], 'time' => time()));
    			} else {
    				update_post_meta( $item, 'wcdp_total_revenue', array('revenue' => 0, 'time' => time()));
    			}
    		}
    	}

    You have any idea why now I get the value on other language and not the default language?
    First I had on Hebrew language the value, now it changed to English.
    Thank you for your help.

    Thread Starter yotamdahan

    (@yotamdahan)

    pll_get_post_translations returns array of ids of the post/product translation.
    So I have tried to run it with foreach loop to display equal values for all translations IDS but no success there.

    Plugin Author flinnn

    (@flinnn)

    You have to add up the individual donation revenues.
    Therefore, create two loops, in the first you add the values together, in the second you save the calculated value for all child products.

    Thread Starter yotamdahan

    (@yotamdahan)

    @flinnn I’m trying to do this, but didn’t quite understand how to.
    when is your update scheduled? it’s really important to my client.

    Plugin Author flinnn

    (@flinnn)

    I will hopefully finish the update today, I think it should be just a few more days until it is fully tested and released.

    Thread Starter yotamdahan

    (@yotamdahan)

    @flinnn You’re great! thank you alot, really appreciate your job here.

    Plugin Author flinnn

    (@flinnn)

    Hi, I have adapted the shortcode for you. With the latest version, you can specify additional products via the parameter addids, the revenue will then be added: https://wcdp.jonh.eu/documentation/usage/progress-bar-shortcode/
    At the same time, I have now extended the plugin with a Polylang integration. This means that the revenue for translated products is now automatically included in the calculation.

    Thread Starter yotamdahan

    (@yotamdahan)

    @flinnn Amazing job, thank you.

Viewing 11 replies - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.