For any reason, you could change the “Add to Cart” text in your single product page in WooCommerce.

Maybe you are based in UK, so it would be “Add to Basket” and you don’t want to use the plugin translation, or simply you want it to say something cool and unique.

There’s a way to change the text on all products with a filter.

Open the file functions.php located in wp-content/themes/your-theme-name/ and add this code at the end of the file:

This code will change the button text on all your products. What if you want to change it conditionally, in example, based on the product type?

There’s a little change you need in the previous code. It should be like this:

In this code we check the product type and return a different text based on that.
You can obviously add more types if you want to. For example if you use WooCommerce Photography you could add the type photography.

28 replies
  1. michele
    michele says:

    Thanks for your post,
    I’m trying to change the other text label of the botton “check out” but I don’t know how using your code with other bottons 🙁

    Reply
    • Nicola Mustone
      Nicola Mustone says:

      Hi Michele,
      Add this code in the file functions.php located in your theme folder in wp-content/themes/your-theme-name/.

      https://gist.github.com/a857302a4654cf4aee6e

      If you want, you can also edit the file directly from the dashboard in WordPress. To do so, navigate to Appearance > Editor and find the file Theme Functions (functions.php) in the list on the right of the page, like in this screenshot: https://cld.wthms.co/12U9T

      If you file ends with the sign ?> be sure to add the code one line before this sign.

      Be sure to chang ethe text “Proceed to Checkout” to what you need.

      Reply
  2. Grant
    Grant says:

    Thanks for this snippet. What if I wanted to change the text conditionally by Product ID, rather than type? How could I provide the conditions for say, 3 specific product IDs with a default “add to cart message” covering everything else?

    Reply
  3. Dzulhelmi
    Dzulhelmi says:

    Hi Nicola,

    This post is the closest solution that i found for my problem. My problem is how can i change the Add to cart text and its URL only for CERTAIN product?

    Not product type, but certain product. I think this is possible since each product has different product ID.

    Reply
      • Kristyn
        Kristyn says:

        Hi there,

        I’m only changing one of my variable products to have a button that says “Donate”. I used the above conditional code with the change you suggest here and it has done nothing to the button on that product’s page.

        I only include case ‘productid’ : $text = ‘Donate’; break; and then left the default.

        Did I do something wrong?

        Reply
        • Nicola Mustone
          Nicola Mustone says:

          Hi Kristyn,

          Like I said in my comment above, you need to change the switch line to use $product->id instead of $product->product_type.

          Then in the case, use the product ID, like case 123:, where 123 is the product ID.

  4. Alex
    Alex says:

    Hi there

    Can anybody help me, tell me how to remove SINGLE PRODUCT PAGES in WooCommerce?

    I want by clicking on the picture of a product from the catalog, the right to open direct affiliate link, both of this page.

    https://bit.ly/1YMLmJL

    Best Regards.

    Reply
  5. Daniele
    Daniele says:

    Hi Nicola,
    i need to change the text conditionally by product category.
    i’ve try in this way but don’t work:

    function wc_custom_single_addtocart_text( $text, $taxonomy ) {
        switch ( $taxonomy->product_cat ) {
            case 'Red'  : $text = 'Prenotazione'; break;
            case 'Regalo': $text = 'Acquista Regalo'; break;
            default        : $text = 'Acquista'; break;
        }
    
        return $text;
    }
    add_filter( 'woocommerce_product_single_add_to_cart_text', 'wc_custom_single_addtocart_text', 10, 2 );
    
    Reply
    • Nicola Mustone
      Nicola Mustone says:

      Hi Daniele,
      Your code can’t work because the second function argument is not really $taxonomy. You added that, but the filter passes the product object as argument, not the taxonomy.

      Change $taxonomy to $product. Then inside the function, use $product_cats = wp_get_post_terms( $product->id, 'product_cat' ); to get the product’s categories. It will be an array.

      After that you can check if the array contains a specific category, and return a different text accordingly.

      Reply
      • Daniele
        Daniele says:

        I’ve change code in this way, but doesn’t work:

        function wc_custom_single_addtocart_text( $text, $product ) {
        $product_cats = wp_get_post_terms( $product->id, 'product_cat' );
            switch ( $product->product_cat ) {
                case 'RISTORANTI'  : $text = 'Utilizza il codice del tuo regalo'; break;
                case 'REGALI': $text = 'Acquista un Regalo'; break;
                default        : $text = 'Acquista'; break;
            }
        
            return $text;
        
        }
        add_filter( 'woocommerce_product_single_add_to_cart_text', 'wc_custom_single_addtocart_text', 10, 2 );
        
        Reply
  6. Daniele
    Daniele says:

    the code does not work either in this way, using the id category 🙁

    add_filter( 'woocommerce_product_single_add_to_cart_text', 'funzione_cat_add_to_cart_text' );
    function funzione_cat_add_to_cart_text( $default ) {
        global $post;
        $terms = get_the_terms( $post->ID, 'product_cat' );
        if ( array_key_exists( 10, $terms ) ) {
                $default = 'UTILIZZA IL CODICE GIFT CARD';
        } else {
            return $default;
        }
    }
    
    Reply
  7. Pam
    Pam says:

    Hey! I just had the same question (how to change add to cart text based on category) and found some snippets that use the cat ID but it didn’t work. Your example above worked for me and I wanted to say THANKS! So, THANKS!

    Reply
  8. Stephen
    Stephen says:

    Hi Nicola,

    I checked the github code you share but i’m wondering what figure to replace. Is it possible to replace the text in two parent categories. Will it apply to the children categories? Been stuck with this problem for quite a while.

    I appreciate any help. Thanks!

    Reply
    • Nicola Mustone
      Nicola Mustone says:

      Hi Stephen,
      Where you see this code:

      if ( $term->name == 'Posters' ) {
      

      You should change it by adding all the categories you want to change:

      if ( $term->name == 'Posters' || $term->name == 'Something' ) {
      

      This will change the text for the categories named Posters and Something. It does not apply to children categories automatically.

      Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

You have to agree to the comment policy.

This site uses Akismet to reduce spam. Learn how your comment data is processed.