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:
add_filter( 'woocommerce_add_cart_item_data', 'my_wpo_translate_cart_meta_with_wpml', 20, 4 );<br />function my_wpo_translate_cart_meta_with_wpml( $cart_item_data, $product_id, $variation_id, $quantity ) {<br /> if ( empty( $cart_item_data['wpo_options'] ) ) {<br /> return $cart_item_data;<br /> }<br /> if ( ! class_exists( '\Barn2\Plugin\WC_Product_Options\Plugin_Factory' ) ||<br /> ! class_exists( '\Barn2\Plugin\WC_Product_Options\Integration\WPML' ) ||<br /> ! class_exists( '\Barn2\Plugin\WC_Product_Options\Model\Option' ) ) {<br /> return $cart_item_data;<br /> }<br /> $plugin = \Barn2\Plugin\WC_Product_Options\Plugin_Factory::create( '', '' );<br /> $wpml_integration = new \Barn2\Plugin\WC_Product_Options\Integration\WPML( $plugin );<br /> foreach ( $cart_item_data['wpo_options'] as $option_id => &$option_data ) {<br /> $option = \Barn2\Plugin\WC_Product_Options\Model\Option::find( $option_data['option_id'] ?? 0 );<br /> if ( ! $option ) {<br /> continue;<br /> }<br /> $translated_name = $wpml_integration->translate_string( $option->name, $option, 'option_name' );<br /> $option_data['name'] = $translated_name;<br /> if ( empty( $option_data['choice_data'] ) || empty( $option->choices ) ) {<br /> continue;<br /> }<br /> $index_by_id = [];<br /> foreach ( $option->choices as $idx => $choice ) {<br /> if ( isset( $choice['id'] ) ) {<br /> $index_by_id[ $choice['id'] ] = $idx;<br /> }<br /> }<br /> $values = is_array( $option_data['value'] ) ? $option_data['value'] : [ $option_data['value'] ];<br /> foreach ( $option_data['choice_data'] as $i => &$choice_data ) {<br /> if ( ! isset( $choice_data['label'] ) ) {<br /> continue;<br /> }<br /> if ( empty( $index_by_id ) ) {<br /> continue;<br /> }<br /> $value_for_this_choice = $values[ $i ] ?? null;<br /> if ( ! isset( $index_by_id[ $value_for_this_choice ] ) ) {<br /> continue;<br /> }<br /> $choice_index = $index_by_id[ $value_for_this_choice ];<br /> $original_label = $option->choices[ $choice_index ]['label'];<br /> $choice_data['label'] = $wpml_integration->translate_string( $original_label, $option, 'choice_label', $choice_index );<br /> }<br /> }<br /> return $cart_item_data;<br />}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.
This topic contains 18 replies, has 1 voice.
Last updated by 5 months, 2 weeks ago.
Assisted by: Otto.