Changing the WooCommerce Cart Item Count Text

Written by Dan Mossop

If you setup a WooCommerce store on the Divi Theme, the header will display a count of the items in the user's cart. The text for this will be of the form "2 Items". If you’d like to change this text, e.g. to translate it into another language, you can use the following PHP code:

add_filter('ngettext_with_context', 'dbc_change_woocommerce_item_text', 20, 6);

function dbc_change_woocommerce_item_text($translation, $single, $plural, $number, $context, $domain ) {
    if ($domain == 'Divi') {
		if ($translation == '%1$s Item') { return '%1$s Article'; }
		if ($translation == '%1$s Items') { return '%1$s Articles'; }
    }
    return $translation;
}
The code above example replaces the English text (both singular and plural forms) with the French equivalent (I hope – please correct me if I have mistranslated). The %1$s in the above is a placeholder which will be replaced with the actual number of items when Divi outputs the page.

Run PHP Code Directly in your Divi Layouts

Unlock endless customization, automation, and dynamic functionality by seamlessly adding PHP code to your Divi pages and posts with the Divi PHP Code Module. Style, preview, and debug your PHP creations directly in the visual builder with robust error handling and enhanced security.

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

4 Comments

  1. I just wanted to stop in to let you know how much I absolutely love your content. Your guides and plugins have not only saved me so much time and frustration, but have directly improved my quality of life. I use your plugins on every single one of my websites, and they are numerous. I hope you keep doing what you do. Thank you!

    Reply
    • You’re very kind, Abigail. Thanks to you too :)

      I’m glad the guides and plugins have been helping. If there’s ever anything you’re trying to do that you don’t see covered anywhere, just let me know. Cheers!

      Reply
  2. Thanks! But in which PHP file should I add this code?

    Reply

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

Your email address will not be published. Required fields are marked *.

We may earn a commission when you visit links on our website.

Latest Posts

Set Custom CSS IDs for Individual Divi Accordion Items

Assigning unique CSS IDs to specific Divi Accordion items allows for precise control over styling, targeting, and linking within your page content. This ability is particularly useful when you want to apply custom designs or create anchor links to particular accordion...

Enable Swipe Navigation in the Divi Gallery Lightbox

Enabling swipe navigation in the Divi Gallery module's lightbox allows users to seamlessly browse through gallery images by swiping left or right, creating a more interactive and mobile-friendly experience. This functionality can significantly improve user engagement...

Disable Slide-In Animation for Divi Gallery Grid Images

Control how images appear in your Divi Gallery module by toggling the slide-in animation effect for grid layouts. Disabling the slide-in animation allows gallery images to load instantly and appear statically, providing a faster and distraction-free browsing...

Control Image Count Display in Divi Gallery Lightbox

Displaying or hiding the image count in the Divi Gallery module’s lightbox can help customize the user experience, depending on whether you want to give visitors an indication of gallery progress or prefer a cleaner, distraction-free view. The ability to toggle this...

Hide Gallery Image Titles in the Divi Lightbox Overlay

Displaying image titles in the lightbox overlay of the Divi Gallery module can sometimes be distracting or unnecessary, depending on your website’s design and user experience goals. Hiding these titles creates a cleaner and more focused viewing experience for visitors...

Random Posts