Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client was experiencing an issue where category names were displayed in different languages on a WooCommerce site with Redis Cache enabled. This occurred when the product was translatable and set to 'use translation if available or fallback to default language', and the product did not have a translation.

Solution:
We provided a workaround involving the insertion of custom PHP code into the theme's functions.php file. This code ensures that when Redis Cache is enabled, the correct language for product terms is used.

<!-- Custom PHP code provided by WPML support --><br />add_filter('woocommerce_get_product_terms', function($terms, $product_id, $taxonomy, $args){<br />    global $sitepress;<br /><br />    if (method_exists($sitepress, 'is_display_as_translated_post_type') && $sitepress->is_display_as_translated_post_type('product')) {<br />        $args['wpml_lang'] = apply_filters( 'wpml_current_language', null );<br />        return _wc_get_cached_product_terms( $product_id, $taxonomy, $args );<br />    }<br /><br />    return $terms;<br />}, 10, 4);<br />

If this solution does not seem relevant to your situation, please do not hesitate to open a new support ticket with us.

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.

Tagged: 

This topic contains 21 replies, has 2 voices.

Last updated by Kor 1 year, 5 months ago.

Assisted by: Kor.

Author Posts
December 23, 2023 at 3:21 am #15122011

kristianP-7

I tried adding all of the object cache keys to the list like this in function.php:

add_action( 'wpml_st_before_remove_strings', 'wp_cache_flush' );
wp_cache_add_non_persistent_groups( [
'*',
'posts*',
'posts',
'*posts',
'global-posts',
'blog-details',
'blog-id-cache',
'blog-lookup',
'global-posts',
'networks',
'rss',
'sites',
'site-details',
'site-lookup',
'site-options',
'site-transient',
'users',
'useremail',
'userlogins',
'usermeta',
'user_meta',
'userslugs',
'redis-cache',
'blog_meta',
'network-queries',
'site-queries',
'user-queries',
'convert_url',
'element_translations',
'get_pages_adjust_ids',
'get_user_admin_language',
'translation_priority_relationships',
'translationmanagement--get_translation_job_id',
'wpml_cache_terms_per_lang',
'wpml_endpoints_support',
'wpml_pre_option_page',
'wpml_register_string_filter',
'wpml_register_string_filter--facetwp',
'wpml_slug_translation_records--post',
'wpml_slug_translation_records--taxonomy',
'wpml_st_cache',
'wpml_term_translation',
'wpml_tm_blog_translators--has_translators',
'wpml_wp_cache__group_keys',
] );

And even tried adding these directly to wp-config.php like shown in object cache documentation. hidden link

define('WP_REDIS_CONFIG', [
'non_persistent_groups' => [
'*',
'posts',
'global-posts',
'blog-details',
'blog-id-cache',
'blog-lookup',
'global-posts',
'networks',
'rss',
'sites',
'site-details',
'site-lookup',
'site-options',
'site-transient',
'users',
'useremail',
'userlogins',
'usermeta',
'user_meta',
'userslugs',
'redis-cache',
'blog_meta',
'network-queries',
'site-queries',
'user-queries',
'convert_url',
'element_translations',
'get_pages_adjust_ids',
'get_user_admin_language',
'translation_priority_relationships',
'translationmanagement--get_translation_job_id',
'wpml_cache_terms_per_lang',
'wpml_endpoints_support',
'wpml_pre_option_page',
'wpml_register_string_filter',
'wpml_register_string_filter--facetwp',
'wpml_slug_translation_records--post',
'wpml_slug_translation_records--taxonomy',
'wpml_st_cache',
'wpml_term_translation',
'wpml_tm_blog_translators--has_translators',
'wpml_wp_cache__group_keys',
],
]);

But still not working correctly

December 23, 2023 at 1:47 pm #15122547

Kor
WPML Supporter since 08/2022

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thanks for your reply.

Glad to know that it works on your staging site. As for the on-going issue on your production site, we will have to check on it. Does it have a different setup? If possible, please share your Website WP admin access here using the private reply option and we'll check on it.

Please note that it is important to have a backup for security purposes and to prevent any potential data loss. You can use the UpdraftPlus plugin (https://wordpress.org/plugins/updraftplus/) to fulfill your backup requirements.

Your upcoming reply will be treated with confidentiality and will only be visible to you and me.

✙ To resolve the issue, I may need your consent to deactivate and reactivate plugins and the theme, as well as make configuration changes on the site if necessary. This emphasizes the significance of having a backup.

December 24, 2023 at 9:40 pm #15125107

kristianP-7

I installed the same theme on staging site and it has the same issue so you can check the staging site.

December 25, 2023 at 2:50 am #15125275

Kor
WPML Supporter since 08/2022

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thanks for your reply.

I've shared your feedback with our 2nd Tier Support for a second look.

January 5, 2024 at 5:48 am #15153218

kristianP-7

Hello, happy new year! Any update on the issue?

January 5, 2024 at 6:09 am #15153228

Kor
WPML Supporter since 08/2022

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thank you for your response.

I regret the oversight on my part. I will review the matter with our 2nd Tier support and will get back to you with an update.

January 12, 2024 at 3:32 pm #15179946

Kor
WPML Supporter since 08/2022

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thanks for your patience.

I have feedback and we have a workaround. Kindly insert the custom PHP code below into your themes functions.php file. Let me know if this works for you.

/**
 * WPML fix for Redis cache.
 * 
 * @link wpmlsupp-11341
 */
add_filter('woocommerce_get_product_terms', function($terms, $product_id, $taxonomy, $args){
	global $sitepress;

	if (method_exists($sitepress, 'is_display_as_translated_post_type') && $sitepress->is_display_as_translated_post_type('product')) {
		$args['wpml_lang'] = apply_filters( 'wpml_current_language', null );
		return _wc_get_cached_product_terms( $product_id, $taxonomy, $args );
	}

	return $terms;
}, 10, 4);
January 13, 2024 at 11:10 am #15181244

kristianP-7

It finally works correctly, thank you! I hope to see the fix included in a future update aswell for other website owners.