Cart in navbar: Translate "0 items"

Hi,

we used X 6.5.6 and updated to Pro 3.1.1 today.
Our translation of the “0 items” next to the cart icon in navbar is now not working anymore. Oddly translations for more than 1 items in cart are still working fine.

We even tried it the hard way with:

add_filter('gettext', 'translate_text');
	add_filter('ngettext', 'translate_text');
	function translate_text($translated) {   $translated = str_ireplace('Items', 'Artikel', $translated);   
	return $translated;
	}

No success. We tried several places for .mo and .po like naming them x-de_DE and putting them in /wp-content/languages/themes and so on. .mo and .po are working as other translations are beeing applied.
Seems to have something to do with the update to (newest version?) of Pro.

Any idea? Thanks!

Ps.: When you look closely the translation (“0 Artikel”) is showing for one second after pageload but is then replaced by “0 items” again.

Hey Alexander,

I’ve replicated this and this is happening in WooCommerce 3.8.0 only. Please downgrade to 3.7.1 as that is currently the supported version. See https://theme.co/apex/forum/t/troubleshooting-version-compatibility/195

I’ll report this issue if this will still be happening on 3.8.0 when it’s supported.

Thanks.

Hi,

sorry, I can’t confirm. We are in fact using 3.7.1, see screenshot.
Thanks.

Hello Alexander,

Please have your PHP code updated and use this:

add_filter('gettext', 'translate_text');
add_filter('ngettext', 'translate_text');
function translate_text($translated) {   
  $translated = str_ireplace('Items', 'Artikel', $translated); 
  $translated = str_ireplace('%d Item', '%d Artikel', $translated);
  $translated = str_ireplace('%d Items', '%d Artikel', $translated);
  return $translated;
}

We would love to know if this has worked for you. Thank you.

Sorry, that’s not working. It’s the same behaviour as before: It’s briefly showing “Artikel” on page load, for approx. 1 sec. or less and then going back to “Items”.
What do you see? Here

Hi Alexander,

The code provided by Ruenel actually works on my end.

There might be something on your end that is conflicting it, please do the following:

  • Clear all the site caches (plugin, server-side, CDN, and browser’s cache) so that the code from the latest release is always in use. This will help you to avoid any potential errors. Please deactivate this caching features while we tackle this issue. Try incognito/Private mode of the browser.

  • Test for a plugin conflict. You can do this by deactivating all third party plugins, and seeing if the problem remains. If it’s fixed, you’ll know a plugin caused the problem, and you can narrow down which one by reactivating them one at a time.

Let us know how it goes,
Cheers!

Found the “Bad guy”. It’s caching tool WP Rocket. Problem is: We haven’t changed anything in the settings of WP Rocket. What we changed is to update X to Pro. We’ve tried to deactivate some settings of WP Rocket on our staging like css-minifier and so on but it seems that just enabling WP Rocket without most of the settings is causing the problem.

Do you have a clue of

  1. which files of Pro to exclude from caching? Which files are related to your cart in header section?
  2. in which file the translation for the cart is written? Maybe we can override this a copy in with child theme or with some hook in functions.php?

We really need WP Rocket and we need Pro now because it’s so much cooler than normal X and showing “items” to our German customers is confusing for them.

Thank you!!

Hey Alexander,

Thanks for testing for where the conflict comes from. I actually do have caching set up in my test site and I’ve just recently discovered that the issue persists in 3.7.1 too. It’s really tricky to test with caching on.

I also should have added that I’ve tried several custom code variations (included your code) to override the behavior but they don’t work (reverts to the last state). But, this only happens when the page is cached.

Check out the video below. It even overrides the setting of the Theme Options and not just translation. And, that’s using the latest parent theme.

If the page is not cached like loading the page in incognito mode, the cart is working fine out of the box. This is the case for first time buyers of your site.

If the page is cached and if you add an item to the cart, the Menu Cart updates and the issue in the video shown above is resolved. This might be the case for repeat buyers so you might currently want to post a notification on your site that buyers should clear browser cache or update the cart.

With that discovery, this issue boils down to caching. WooCommerce pages should really not be cached and this includes all pages that use WooCommerce modules like the Menu Cart. I know that caching is important but if you wish to use the Menu Cart feature, you need to disable caching or WP Rocket for your case. There’s no point of overriding it with custom code like what I’ve said above if the whole page is cached.

I believe something has changed in the WooCommerce system that caused this issue because before, the Menu Cart seems to be resilient to caching. I’ll post this in our issue tracker for further investigation but for now, you need to disable caching.

Thank you for understanding.

Thank you. We will ask WP Rocket if they have an idea.

Let us know how it goes,

Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.