Skip Navigation

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.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 -
- 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 13 replies, has 3 voices.

Last updated by Long Nguyen 1 year, 7 months ago.

Assisted by: Long Nguyen.

Author Posts
February 28, 2023 at 1:14 pm #13135845

T4ng

I am trying to:
Problem already explained here: https://wpml.org/forums/topic/woocommerce-variations-translated-products-prices-wont-update/

Update the price of a product with variations.
Link to a page where the issue can be seen:
hidden link
The price below the title is wrong. Add the product to the cart, and go to the cart, and you'll get the expected price.
I expected to see:
The right price value
Instead, I got:
The product shown on the product page remains the price set for the simple product of the same entity, before the product was changed to a product with variations. Once added to the cart, the price is fine.
Plus several other problems on the way to updating the product.
I'd be happy to test it on a clean install from a sandbox including WPML, WooCommerce and WCML, which you'd provide. Thanks

March 2, 2023 at 4:33 am #13150935

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi there,

Thank you for contacting WPML support, I'd be happy to help you with this issue.

Please follow some troubleshooting steps below and see if it helps.

1. Enable a minimal environment:
- Deactivate all plugins except WPML, WooCommerece and their addons
- Switch to a standard theme of WordPress

2. Go to WPML > Support > Troubleshooting > Click on some buttons below
- [Products and Variations] Synchronize posts taxonomies
- Clear the cache in WPML
- Remove ghost entries from the translation tables
- Fix element_type collation
- Fix WPML tables collation
- Fix terms count
- Fix post type assignment for translations

❌ IMPORTANT: Please backup your database and website before proceeding ❌
You can use this plugin to create the backup: 
https://wordpress.org/plugins/duplicator/

Look forward to your reply.
Thanks

March 3, 2023 at 9:47 am #13162061

T4ng

Hi,
Thanks. I just tested that, and there might be some impact from our theme. Our developers will dig into this next week. Could we please keep that ticket open until we take a look. Thanks

March 4, 2023 at 3:39 pm #13169987

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

Thank you for your feedback.

Take your time and you can reply to this ticket in a few days or create a new one whenever needed.

Thanks.

March 13, 2023 at 4:16 pm #13234827

T4ng

Hi,
It still unclear how and why our theme interfers in this process, since it doesn't manipulates these data.
Our developer should take a look at it in the following days.

March 14, 2023 at 2:01 am #13238017

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

I'm waiting for your feedback.

Thanks,

March 20, 2023 at 3:35 pm #13285915

Sami Radi

Hi,

I'm with the dev team, here are some additional insight and questions regarding this issue.

We have specific regional rules to display the price on our website.
For instance, The price must be displayed with taxes and excluding taxes in Europe.
The price must be displayed excluding taxes in the US.
The price must be displayed with specific number settings according to the region.

We couldn't meet the business requirements with Woocommerce/WCML visual settings only.

We had to hook the

$product->get_price_html();

method to finely tune the price display for each language/region.

add_filter( 'woocommerce_get_price_html', array( $this, 'woocommerce_get_price_html_adjust_locale' ), 10, 2 );

The

woocommerce_get_price_html_adjust_locale

creates the html code that meets our need.

The method uses the native woocommerce

wc_price

,

wc_get_price_including_tax

and

wc_get_price_excluding_tax

functions

For instance :

wc_price( wc_get_price_including_tax( $product ), $args );

Or

wc_price( wc_get_price_excluding_tax( $product ), $args );

are used to generate the HTML code with the tax included/excluded price and the correct formatting in it.

We have products with variations that have a regular price in $ (dollar - 270$) and a custom regular price in € (euro - 285€).

The products original language is US.

Our code cannot get the custom regular price for variations in € on the product page using the

wc_get_price_including_tax

or

wc_get_price_excluding_tax

functions.

Without our filter hook, the

$product->get_html_price();

seems to get the variations custom regular price correctly but the formatting of the price is not correct.

With the filter hook, we only manage to get the original product regular price including taxes (with currency conversion: 270$ => ~268€, it should be the default variation custom regular price : 285€).

After digging, i found out (or so it seems) that the

wc_get_price_including_tax

and

wc_get_price_excluding_tax

were not hooked by WCML because the woocommerce native functions directly call the

product->get_price();

method to perform calculation. And It seems that this method do not have an official filter hook.

I hooked WCML to the woocommerce native

product->get_price();

method using a PHP decorator like this :

class WC_Product_Proxy
{
	private $product;

	/**
	 * @param \WC_Product $product Fully qualified product object.
	 */
	public function __construct(\WC_Product $product) {
			$this->product = $product;
	}

	public function get_price() {
		// Default price.
		$null      = $this->product->get_price();
		// Product id
		$object_id = $this->get_id();
		// WCML price meta key
		$meta_key  = '_regular_price';
		// Single price
		$single = true;
		// Calling WCML price filter
		$price = apply_filters(
				'get_post_metadata',
				$null,
				$object_id,
				$meta_key,
				$single
		);
		return $price;
	}

	public function __call($name, $arguments) {
			return call_user_func_array(array(&$this->product, $name), $arguments);
	}

	public function __get($name) {
			return $this->product->$name;
	}

	public function __set($name, $value) {
			$this->product->$name = $value;
	}
}

And then i used the Decorator as follows :

wc_price( wc_get_price_including_tax( new WC_Product_Proxy( $product ) ), $args );

Or

wc_price( wc_get_price_excluding_tax( new WC_Product_Proxy( $product ) ), $args );

When the

$product->get_price()

method is called from inside the

wc_get_price_including_tax

or

wc_get_price_excluding_tax 

functions, it goes through my custom Decorator code and gets the custom regular price provided by WCML (according to debug logs that i positionned inside WCML).

But WCML does not get the product variation custom regular price (285€). It seems to only get the product regular price with currency converted (268€).

Do you have any insight on how i might have the

wc_get_price_including_tax

and

wc_get_price_excluding_tax

method get the custom regular price for default variations ?

March 21, 2023 at 1:31 am #13288915

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

Thank you for the feedback.

So the issue here is the custom code created by the developer in the child theme that impacts the variation price on the frontend. I would like to inform you that helping you with custom code, is out of the scope of WPML, but you can try to take a look at the filter hook "wcml_product_price_by_currency" to get the product custom price
https://wpml.org/documentation/related-projects/woocommerce-multilingual/wcml-hooks-reference/#hook-1112680

If you are not able to accomplish this, I would recommend you contact one of our certified partners that will be more than happy to help you with this. In this link, you will find a list of our certified partners: https://wpml.org/contractors/

Thanks for your understanding and patience.

March 21, 2023 at 8:08 am #13290605

Sami Radi

Ok let's assume we remove the custom code and use the

$product->get_price_html()

method. The method only gets us the custom regular price including taxes.

Is there a way to get the custom regular price excluding taxes through WCML or any hooked woocommerce native function ?

March 21, 2023 at 10:13 am #13292055

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

Thank you for your feedback.

I'm afraid that there is no built-in function of WCML that supports getting the custom price with/without tax. You can try to use the filter "wcml_product_price_by_currency" to get the custom price by currency and calculate it with the tax on your site by coding. And the filter "wpml_object_id" to get the product ID in a specific language.
Please read more on the documentation
https://wpml.org/documentation/related-projects/woocommerce-multilingual/wcml-hooks-reference/#hook-1112680
https://wpml.org/wpml-hook/wpml_object_id/

I hope I was helpful. Don't hesitate to ask if you find any problem along the way, I'll gladly help you.

March 21, 2023 at 11:16 am #13292809

Sami Radi

Hi,

Thanks for the answer, so it looks like we'll need some custom code that impacts the variation price on the frontend after all.

March 22, 2023 at 1:16 am #13298431

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

Yes, some custom code is needed to get the product custom price on the frontend.

Let us know if you have any questions.

March 27, 2023 at 3:23 pm #13340379

T4ng

This development looks quite difficult, so we're not willing to invest into it.

By the way, I located, in the database, the data displayed in the frontend with our theme and custom code.
I checked locally that modify that value allows to show the modified (thus expected) value on the frontend. As far as I know that global product (single/parent) product price is useless when configured as variation product. This could be a quick workaround for us.
That data is located in the post_meta table :
post_id = {the global product ID, as opposed to its variations}
meta_key="_price_EUR"

Is there any possible side effect to expect when modifying this value directly in the database?

Thanks

March 28, 2023 at 3:44 am #13344767

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

Thank you for your feedback.

There is no option to set the price for the parent product if it has variations, and thus, there is no custom price in the second currency for the parent product (meta key _price_EUR).

So you can update this meta key and value for the parent product as you want, it is not used anywhere.

Regards.

The topic ‘[Closed] The product shown on the product page for product with variation is wrong’ is closed to new replies.