This thread is resolved. Here is a description of the problem and solution.
Problem:
You are using the Advanced Product Fields plugin for WooCommerce and have successfully translated the product options on the product page. However, when products are added to the cart, the option values still appear in the original language, not the translated version.
Solution:
We recommend adding the following code to the
functions.php
file of your theme. Please ensure you perform a full site backup before implementing this code:
// Add the filter with a higher priority (lower number) than the plugin's filter add_filter('get_post_metadata', 'translate_wapf_fieldgroup_post_meta', 10, 4); function translate_wapf_fieldgroup_post_meta($value, $post_id, $meta_key, $single) { if ($meta_key === '_wapf_fieldgroup') { // Temporarily remove the filter to avoid infinite loops remove_filter('get_post_metadata', 'translate_wapf_fieldgroup_post_meta', 10); // Get the original meta value $fieldgroup_meta = get_post_meta($post_id, $meta_key, false); // Re-add the filter add_filter('get_post_metadata', 'translate_wapf_fieldgroup_post_meta', 10, 4); if (!empty($fieldgroup_meta) && is_array($fieldgroup_meta)) { foreach ($fieldgroup_meta as &$group) { if (isset($group['id']) && preg_match('/p_(\d+)/', $group['id'], $matches)) { $post_id = $matches[1]; $translated_post_id = apply_filters('wpml_object_id', $post_id, 'post', true); $group['id'] = str_replace("p_$post_id", "p_$translated_post_id", $group['id']); } } } return $fieldgroup_meta; } return $value; }
This solution addresses the issue where the plugin stores the Advanced Product fields in _wapf_fieldgroup as a multidimensional array, which may not update correctly across different languages in the cart.
Please note, this workaround may not function correctly if languages are switched on the Cart or Checkout pages. To prevent potential issues, enable the "Prompt for a confirmation and reset the cart" option. For more details, see this article.
If this solution does not resolve your issue or seems outdated, please check related known issues, verify the version of the permanent fix, and confirm that you have installed the latest versions of themes and plugins. If needed, do not hesitate to 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.
No supporters are available to work today on this forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
This topic contains 3 replies, has 2 voices.
Last updated by 4 months, 2 weeks ago.
Assisted by: Bigul.