skip to Main Content

I’m trying to change text of the update cart button. Please I need the code in functions.php file which can change/edit ‘update cart’ text in the cart page in Woocommerce.
thanks,

4

Answers


  1. Find: >> cart.php

    Then Find:

    <button type="submit" class="button" name="update_cart" value="<?php esc_attr_e( 
    'Update cart', 'woocommerce' ); ?>"><?php esc_html_e( 'Update cart', 'woocommerce' ); 
    ?></button>
    

    Try changing the second ‘Update cart’ and tell me what happens.

    Login or Signup to reply.
  2. You can copy and paste the below function to your functions.php and change the text. This works. Tested

    function change_update_cart_text( $translated, $text, $domain ) {
        if( is_cart() && $translated == 'Update cart' ){
            $translated = 'New Text Here';
        }
        return $translated;
    }
    add_filter( 'gettext', 'change_update_cart_text', 20, 3 );
    
    Login or Signup to reply.
  3. Another way to get at this text is to copy the wp-content/plugins/woocommerce/templates/cart/cart.php file to your theme at wp-content/themes/YOUR_RAD_THEME/woocommerce/cart/cart.php

    From there you can search that file for "Update cart". You should find it in two places inside a button tag.

    <button type="submit" class="button" name="update_cart" value="<?php esc_attr_e( 'Update cart', 'woocommerce' ); ?>"><?php esc_html_e( 'Update cart', 'woocommerce' ); ?></button>

    Update the second one <?php esc_html_e( 'Update cart', 'woocommerce' ); ?> to whatever text you need. Bonus is that you can also edit other parts of the cart using that file.

    I would avoid using gettext because that’s a global WordPress filter. In other words, it’s going to replace your string anyplace on the site, not just that button.

    Login or Signup to reply.
  4. Thanks @melvin i tried this code for Turkish. Worked 🙂

    if you should paste your functions.php. Don’t forget change here ‘Sepeti Güncelle’

    function change_update_cart_text( $translated, $text, $domain ) {
        if( is_cart() && $translated == 'Update cart' ){
            $translated = 'Sepeti Güncelle';
        }
        return $translated;
    }
    add_filter( 'gettext', 'change_update_cart_text', 20, 3 );
    
    function change_update_apply_coupon( $translated, $text, $domain ) {
        if( is_cart() && $translated == 'Apply coupon' ){
            $translated = 'Kuponu Uygula';
        }
        return $translated;
    }
    add_filter( 'gettext', 'change_update_apply_coupon', 20, 3 );
    
    function change_update_coupon_code_text( $translated, $text, $domain ) {
        if( is_cart() && $translated == 'Coupon code' ){
            $translated = 'Kupon Kodu';
        }
        return $translated;
    }
    add_filter( 'gettext', 'change_update_coupon_code_text', 20, 3 );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search