This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 9 replies, has 2 voices.

Last updated by Bigul 1 week, 5 days ago.

Assigned support staff: Bigul.

Author Posts
September 12, 2019 at 4:36 pm #4563425

George L.

The rounding of prices is firing at the wrong place for composite products

Steps to reproduce
1. Create a simple product. Set the price to £5
2. Create a second simple product. Set the price to £6
3. Create a new currency (for example €) and set it at 1.1
4. Set the currency to round to the nearest integer -> Up
5. Set the Increment for nearest integer -> 1
6. Create a composite product and add the two simple products as components
7. Set the components to be priced individually
8. Set a discount for 10% to each component
9. Preview the composite product

Expected Results in £
The first component should be £5 - 10% = £4.5
The second component should be £6 - 10% = £5.4
The total should be €9.9

Expected Results in €
The first component should be £5 * 1.1 = €5.5 -> round up to €6 - 10% = €5.4
The second component should be £6 * 1.1 = €6.6 -> round up to €7 - 10% = €6.3
The total should then be €11.7

Actual Results in €
The first component is shown as €6
The second component is shown as €7
The product total is shown as €12

p.s. I cannot provide a copy of our database but the issue can be reproduced on vanilla installations when only just the core plugins are activated

September 13, 2019 at 1:28 pm #4568835

George L.

Upon further investigation, this issue is caused by woocommerce-multilingual\compatibility\class-wcml-composite-products.php Line 37

add_filter( 'raw_woocommerce_price', array( $this, 'apply_rounding_rules' ) );

and and 570-576

public function apply_rounding_rules( $price ) {
	if ( wcml_is_multi_currency_on() ) {
		$price = $this->woocommerce_wpml->multi_currency->prices->apply_rounding_rules( $price );
	}

	return $price;
}

Disabling (or unhooking) this code seems to calculate the price correctly.

I've updated the test product further to demonstrate the issue better.

As you can see on those screenshots, the calculations are incorrect when the filter is there. When the filter is removed, the calculations make more sense.

Since this filter was explicitly added by WPML, I imagine there has to be a reason for it, so a good starting point would be to understand why those reasons.

In our point of view, we would like the components to show rounded up (so €5 instead of €4.57) but the total price should also match and currently it doesn't.

If your intention was to show the components rounded up, then you probably need another filter to recalculate the composite price using the rounded prices.

September 13, 2019 at 5:00 pm #4570203

Bigul
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello,

Welcome to the WPML support forum. I will do my best to help you to resolve these issues.

It looks like a compatibility issue and requires further checking. So I have a request. Is it possible to share the Duplicator copy of the site using the Duplicator plugin - https://wordpress.org/plugins/duplicator/?

I am enabling the private option for the next reply. You can share the package via Google Drive or Dropbox.

--
Thanks!

Bigul

September 13, 2019 at 5:18 pm #4570225

George L.

Hi Bigul, as I mentioned on my first message I cannot provide a copy of the site or the data. As stated before, the issue can be reproduced in vanilla installation so feel free to text for yourself on any installation you have at your disposal.

Also, I have given you clear steps to reproduce and all details including where the code is so please test yourself and escalate asap.

September 14, 2019 at 2:13 pm #4572791

Bigul
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello,

Thank you for the updates. I am trying to reproduce the issue in a fresh installation on our Sandbox server now. But we don't have the latest version of WooCommerce Composite Products.

So please visit the following URL and upload the WooCommerce Composite Products plugin. It will help us to reproduce the issue easily and we can forward it to our developers for further debugging.

hidden link

hidden link

--
Thanks!

Bigul

September 15, 2019 at 10:41 am #4574333

George L.

I have uploaded the latest version of the plugin and configured the products accordingly.

You can preview it at /product/test-composite/

I can see the links on your previous message are hidden when this thread is accessed while logged-out on your forums. I trust those links are only visible to supporters and myself and not logged-in users of your forum?

Please review this issue and escalate asap.

September 16, 2019 at 9:43 am #4578017

Bigul
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello,

Thank you for uploading the plugin and reproducing the issue on Sandbox test site. I have escalated the ticket to our compatibility team for further debugging.

Please note, the links of this ticket will be only visible to you and forum moderators like me.

We will get back to you as early as possible. Please wait.

--
Thanks!

Bigul

September 16, 2019 at 12:01 pm #4579967

George L.

The following code seems to be fixing the bug. It would be good to understand why this is not part of WCML already and if it was intentionally left out.

add_filter('woocommerce_composited_product_raw_price', 'woocommerce_composited_product_raw_price_rounding', 10, 4);
add_filter('woocommerce_composited_product_raw_price_cart', 'woocommerce_composited_product_raw_price_rounding', 10, 4);
function woocommerce_composited_product_raw_price_rounding( $price, $product, $discount, $WC_CP_Product ) {

	if ( '' === $price ) {
		return $price;
	}

	if ( ! $WC_CP_Product->is_priced_individually() ) {
		return (double) 0;
	}

    if ( !wcml_is_multi_currency_on() ) {
        return $price;
    }

	global $woocommerce_wpml;
	$price = $woocommerce_wpml->multi_currency->prices->apply_rounding_rules( $price );

	return $price;
}
September 16, 2019 at 4:56 pm #4582723

Bigul
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello,

Thank you for updates. The ticket is escalated to our compatibility developers and waiting for their feedback now.

Please check the attached images. I have added the code in *functions.php* of the theme. But the issue still exists in the Sandbox test site.

--
Thanks!

Bigul

October 1, 2019 at 1:40 pm #4672467

Bigul
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello,

For your kind updates, the issue is escalated to our developers for fixing. We will get back to you soon when we have an update from our developers on this. Please wait. Thank you for your patience.

--
Thanks!

Bigul