• Resolved bielgirao

    (@bielgirao)


    Hey, I’m working on a new e-commerce site and my actual language it’s Portuguese. My theme and my plugin are 100% translated. But when I click on the cart icon in the header section, the cart popup appears with an English message when the cart is empty. Can I change this message manually with a php function? Can someone help me with this?

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi there

    You could try adding this to your functions.php file, ensure you are using a child theme so that should you update the theme you don’t loose the function :

     function change_no_product_text($translated) {
       $translated = str_ireplace('No products in the cart.', 'insert your translation here', $translated);
       return $translated;
     }
     add_filter( 'gettext', 'change_no_product_text' );

    Hello @bielgirao ,

    Please use this code in your active themes functions.php,

    
    
    /**
    * Change the “No products in the cart” message over the mini-cart
    *
    */
    
    function ced_text_strings( $translated_text, $text, $domain ) {
    switch ( $translated_text ) {
    case ‘No products in the cart.’ :
    $translated_text = __( ‘new text here’, ‘woocommerce’ );
    break;
    }
    return $translated_text;
    }
    add_filter( ‘gettext’, ‘ced_text_strings’, 20, 3 );

    Thanks,

    • This reply was modified 4 years, 9 months ago by cedcommerce.
    Thread Starter bielgirao

    (@bielgirao)

    Hey guys, thanks for helping me but none of the options is working. The code from @robinrsa don’t change the text and the code from @cedcommerce it’s giving me the following error: syntax error, unexpected ‘products’ (T_STRING).

    Previously I used this code to change a text that was wrong also:

    add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
    function wcs_custom_get_availability( $availability, $_product ) {
        
        // Change In Stock Text
        if ( $_product->is_in_stock() ) {
            $availability['availability'] = __('EM ESTOQUE!', 'woocommerce');
        }
        // Change Out of Stock Text
        if ( ! $_product->is_in_stock() ) {
            $availability['availability'] = __('ESGOTADO!', 'woocommerce');
        }
        return $availability;
    }

    I was thinking to use the same idea for this problem but I don’t know how to do it because I’m bad at this code language. Can you guys help me? The text I want in place of “No products in the cart.” is “Sem produtos no carrinho.”

    Thanks!

    Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there,

    You can do this by using a free translation plugin like Loco Translate. This will allow you to find that phrase and change it to be what you’d like.

    There’s a great guide for this available here:
    https://danielsantoro.com/using-loco-translate-change-wordpress-strings/

    translation
    Link to image: https://d.pr/i/JmedIq

    I hope that helps! Have a wonderful day!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Changing “No products in the cart.” text’ is closed to new replies.