[Resolved] woocommerce - product options - and cart
This thread is resolved. Here is a description of the problem and solution.
Problem: If you're experiencing issues with WooCommerce Product Options not translating product options and 'Estimated Total' in the cart when using the Greek language on your WooCommerce site, this might be due to the plugin storing untranslated option names and choice labels in the cart meta. Solution: We recommend trying the following workaround. First, ensure you back up your website completely. Then, add the following code to your theme's functions.php file:
Please note, this workaround has limitations, such as not re-translating labels if the language is changed after products are added to the cart. For a permanent fix, we will need to contact Barn2 for an update to their integration.
If this solution does not resolve your issue or seems irrelevant due to being outdated or not applicable to your case, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If issues persist, please open a new support ticket at WPML support forum.
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.
Background of the issue:
I am trying to launch a new product on my WooCommerce site. I need to select the Greek language page, select the product, and go to the Cart to see the issues.
Symptoms:
The client did not specify the exact issue or error message encountered when trying to view the product in the Cart.
Questions:
What issues are occurring when selecting the Greek language page and viewing the product in the Cart?jeanneK : Go to hidden link
Select Greek language flag
On this page Select the three tiles - one above other
Enter messages
Order
Go to Cart
See there what is still appearing in English
2 things
Product options - specific to customer
and
'Estimated Total' standard on template
Product Options (specific to Customer0 and Estimated Total (specific to template) not being translated
: Go to hidden link
Select Greek language flag
On this page Select the three tiles - one above other
Enter messages
Order
Go to Cart
See there what is still appearing in English
2 things
Product options - specific to customer
and
\'Estimated Total\' standard on template
Product Options (specific to Customer0
and E
stimated Total (specific to template) not being translated
To ensure the quickest and most accurate support, please provide your debug information so I can look at some of your configurations. We have an excellent article on how to locate it here: https://wpml.org/faq/provide-debug-information-faster-support/.
I would like to request temporary access (wp-admin and FTP) to your site to take a better look at the issue.
It would be better to a testing site where the issue is replicated.
The information you will enter is private which means only you and I can see and have access to it.
Maybe I'll need to replicate your site locally. For this, I'll need to temporarily install a plugin called “Duplicator” or "All in One WP Migration" on your site.
This will allow me to create a copy of your site and your content.
Once the problem is resolved I will delete the local site.
**IMPORTANT**
- Please make a backup of site files and database before providing us access.
- If you do not see the wp-admin/FTP fields this means your post & website login details will be made PUBLIC. DO NOT post your website details unless you see the required wp-admin/FTP fields.
Best Regards,
Otto
WPML Support Team
OnTheGoSystems http://www.onthegosystems.com
The makers of WPML, Toolset and ICanLocalize
But I do not know where to access thatfor the link brings me here, and there is no reply here.
I have backed up and provided Otto with Admin access using the email address in the email I recived from him.
Can you please try the workaround suggested there?
Regarding the options' product strings, the WooCommerce Product Options plugin documentation claims that it should be translated via WPML > String Translation: hidden link
I noted that they are already translated but don't display in the front end. I also noted that the cart in English uses the regular WooCommerce cart, but in Greek it uses a different version, which seems to use Javascript. And that may be the reason why it's not translating.
The cart translation needs to be updated, so it's synched with the default language cart.
Please try the following:
❌ Please make a full website backup before proceeding ❌
- Go to pages, Cart and edit the translation (check the screenshot attached)
- Complete all the segments (100%) and save it
- Check if the issue persists
- Don't ignore the backup warning, please 🙂
I made a copy of your site to debug, but I can't test this myself because the WooCommerce Product Options license deactivated in my local environment. Do they provide development keys? If so, can you share it with me so I can test it? If needed, the URL of my local site is: hidden link
I tried both workarounds either with Maya or the support assistant a day or so ago. He then asked for credentials and I had to ask our developer to back up - and that support person closed that ticket in the mean-time.
Re Barn2 for developer - nothing needed
See this link - apparently keeping you logged in is a wordpress matter : hidden link
Make sure the box "Send me an email when I receive a reply to a support question" is selected.
For the license, is it possible to contact WooCommerce Product Options team for a testing license or assign your current license to hidden link temporarily, we can then debug this locally,
Re
the email notifications,
"Send me an email when I receive a reply to a support question" box - is already selected.
and the email address is valid - but no notifications are being received when this support log is updated!
Re
For the license,
I contacted Barn2 product options today and requested a developer key, but they have yet to reply.
Re:
product options
Here is the license key
a90ef4fddc769a06965363baae83ed4d
But I do not know how to assign our current license to hidden link
I used the key you've provided in my local copy of your site, and now I managed to see the problem and debug it.
The product options are translated on the product page because WooCommerce Product Options explicitly sends those strings through its WPML integration filter (wc_product_options_get_output_string, which calls wpml_translate_string).
However, when an item is added to the cart, the plugin stores the raw (untranslated) option name and choice labels inside its own wpo_options cart meta, and later outputs them in the cart/checkout without passing them back through WPML. This limitation is in the integration on the WooCommerce Product Options side.
As they took care of the integration, we need to reach them to fix it for good.
Meanwhile, I found this workaround:
❌ Please make a full website backup before proceeding ❌
In your theme's functions.php file, paste the following code:
/**
* Translate WooCommerce Product Options texts when adding to cart
* using the plugin's own WPML integration.
*/
add_filter( 'woocommerce_add_cart_item_data', 'my_wpo_translate_cart_meta_with_wpml', 20, 4 );
function my_wpo_translate_cart_meta_with_wpml( $cart_item_data, $product_id, $variation_id, $quantity ) {
// If there are no WPO options in this cart item, do nothing.
if ( empty( $cart_item_data['wpo_options'] ) ) {
return $cart_item_data;
}
// Make sure the plugin classes exist (plugin is active and loaded).
if (
! class_exists( '\Barn2\Plugin\WC_Product_Options\Plugin_Factory' ) ||
! class_exists( '\Barn2\Plugin\WC_Product_Options\Integration\WPML' ) ||
! class_exists( '\Barn2\Plugin\WC_Product_Options\Model\Option' )
) {
return $cart_item_data;
}
// Get the plugin instance and the WPML integration helper.
$plugin = \Barn2\Plugin\WC_Product_Options\Plugin_Factory::create( '', '' );
$wpml_integration = new \Barn2\Plugin\WC_Product_Options\Integration\WPML( $plugin );
foreach ( $cart_item_data['wpo_options'] as $option_id => &$option_data ) {
// Load the option model so we can access the original data.
$option = \Barn2\Plugin\WC_Product_Options\Model\Option::find( $option_data['option_id'] ?? 0 );
if ( ! $option ) {
continue;
}
// 1) Translate the option name (the "key" shown in cart/checkout).
$translated_name = $wpml_integration->translate_string( $option->name, $option, 'option_name' );
$option_data['name'] = $translated_name;
// 2) Translate each choice label, if any.
if ( empty( $option_data['choice_data'] ) || empty( $option->choices ) ) {
continue;
}
// Build a map: choice_id => index, to reproduce the same index WPML uses.
$index_by_id = [];
foreach ( $option->choices as $idx => $choice ) {
if ( isset( $choice['id'] ) ) {
$index_by_id[ $choice['id'] ] = $idx;
}
}
// Normalize the stored value to an array (covers both single and multi).
$values = is_array( $option_data['value'] ) ? $option_data['value'] : [ $option_data['value'] ];
foreach ( $option_data['choice_data'] as $i => &$choice_data ) {
if ( ! isset( $choice_data['label'] ) ) {
continue;
}
// For free-text fields, there are usually no predefined choices to translate.
if ( empty( $index_by_id ) ) {
continue;
}
$value_for_this_choice = $values[ $i ] ?? null;
if ( ! isset( $index_by_id[ $value_for_this_choice ] ) ) {
continue;
}
$choice_index = $index_by_id[ $value_for_this_choice ];
$original_label = $option->choices[ $choice_index ]['label'];
// Translate the choice label using the same context and index as when registered.
$choice_data['label'] = $wpml_integration->translate_string(
$original_label,
$option,
'choice_label',
$choice_index
);
}
}
return $cart_item_data;
}
This workaround has the following limitation. If a customer changes language after already having products in the cart, the labels are not “re‑translated”: they remain in the language that was active when the product was added (just like other metadata that stores fixed text). But it's rare switching languages at that stage. If the client changes languages before start shopping and keeps it, it will be OK.
As I mentioned, this is an “external” workaround; the definitive fix should come from Barn2 (which does not pass the cart/checkout texts through its WPML filters).
Please, give it a try and once you confirm we will reach them too so they implement the final solution on their code.