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: Update the price of a product with variations. |
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: 2. Go to WPML > Support > Troubleshooting > Click on some buttons below ❌ IMPORTANT: Please backup your database and website before proceeding ❌ Look forward to your reply. |
March 3, 2023 at 9:47 am #13162061 | |
T4ng |
Hi, |
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, |
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. 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 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. 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. 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.