Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the text of 'View cart' button

Iam using a woocommerce plugin but I got an problem on how to change the text of the view cart button hope there is a one who can help with my problem this is my site this is the image of the text that i want to change the image how can i edit it? all suggestion are appreciated.

like image 798
Jhunmar Tomines Avatar asked Feb 03 '26 09:02

Jhunmar Tomines


2 Answers

Add the following to your functions.php file.

/**
 * Change text strings
 *
 * @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
 */
function my_text_strings( $translated_text, $text, $domain ) {
    switch ( strtolower( $translated_text ) ) {
        case 'View Cart' :
            $translated_text = __( 'View Shopping Cart', 'woocommerce' );
            break;
    }
    return $translated_text;
}
add_filter( 'gettext', 'my_text_strings', 20, 3 );

This will change View Cart to View Shopping Cart

like image 171
Selom Avatar answered Feb 05 '26 01:02

Selom


The example code put forward by Selom works, but is highly inefficient, as it forces all Wordpress text to be converted to lower case and then run through this filter to see if it matches a case. It has an immediate impact on load time as well as functions such as adding to cart. This is especially noticable if you are using ajax to add products to the cart without refreshing the page.

It is far better to only run the text that is from the WooCommerce domain through a filter. This speeds things up a lot.

I recommend using this example code instead, sourced from Rodolfo Melogli:

/**
 * @snippet       Translate a String in WooCommerce
 * @sourcecode    https://businessbloomer.com/?p=162
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.5.4
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_filter( 'gettext', 'bbloomer_translate_woocommerce_strings', 999, 3 );

function bbloomer_translate_woocommerce_strings( $translated, $text, $domain ) {


     if ( ! is_admin() && 'woocommerce' === $domain ) {

      switch ( strtolower( $translated ) ) {

         case 'view cart' :
            $translated = 'View/Edit Order';
            break;

         case 'proceed to checkout' :
            $translated = 'Place Order ';
            break;

          case 'checkout' :
            $translated = 'Place Order ';
            break;

    case 'add to cart' :
            $translated = 'Add to Order';
            break;


         // enter a new case for each line where you want Woocommerce text to be changed.

      }

   }   


    return $translated;
}

like image 35
Josh Moore Avatar answered Feb 05 '26 01:02

Josh Moore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!