How to change the add to cart text on WooCommerce product pages

by | Jan 10, 2023 | Code Snippets | 0 comments

Are you looking to make your WooCommerce store stand out? One simple way to do that is by customizing the text on your product pages. One of the most important pieces of text on any product page is the “Add to Cart” button.

By default, this button says “Add to Cart” on all of your product pages, but you may want to change that to something more fitting for your products or brand. In this post, we will go over how to change the Add to Cart text on your WooCommerce product pages.

Whether you want to change the text for all of your products or just for specific product types, this guide will show you how to do it.

Change the add to cart text using the WooCommerce Builder For Divi

If you are using Divi theme, then our WooCommerce Builder plugin is the best option for you. Changing the add to cart text is very easy to do.

  1. Open the product layout in the theme builder or Divi library.
  2. Add the “add to cart button” module.
  3. Change the text to what ever you like.
How to change the add to cart text on WooCommerce product pages

Change the add to cart text using a code snippet

Using custom code snippets is an efficient method that can be done with minimal effort. Instead of searching for the perfect plugin or relying on pre-made options, a code snippet allows you to add the exact customization you need. Not only is it faster and easier to implement, but it’s also less resource-intensive and it can help keep your website’s loading speed faster.

Change the add to cart text on ALL products

The following code snippet will change the add to cart text on all the product pages at once. All you need to do is to change the Custom Text Here (keep the quotations.)

 * Change the add to cart text for all products
 * @author DiviKingdom.Com
 * @version 1.0
add_action('woocommerce_product_single_add_to_cart_text', 'dkwc_change_add_to_cart_text_product_page');
function dkwc_change_add_to_cart_text_product_page(){
    return 'Custom Text Here';

Change the add to cart text on product pages based on their type

WooCommerce offers several different product types to help you sell a variety of products and services on your online store. The available product types in WooCommerce include:

  • Simple Product: A basic product that can be purchased with a single click. It can have options like size and color, but they will not affect the price of the product.
  • Variable Product: A product that has multiple variations, such as different colors or sizes. Each variation can have its own price, SKU, and stock status.
  • Grouped Product: A collection of related products that can be purchased together. These products are not sold individually, but rather as a group.
  • External/Affiliate Product: A product that is sold by another website or store, but can be promoted and sold on your own website.

And here is the code snippet for that:

 * Change the add to cart text based on the product type
 * @author DiviKingdom.Com
 * @version 1.0
add_action('woocommerce_product_single_add_to_cart_text', 'dkwc_change_add_to_cart_text_besed_type');
function dkwc_change_add_to_cart_text_besed_type($text){
    global $product;
    $type = $product->get_type();
        case 'simple':
            $text = 'Simple add to cart';
        case 'variable':
            $text = 'Variable add to cart';
        case 'grouped':
            $text = 'Grouped add to cart';
        case 'external':
            $text = 'External add to cart';
    return $text;

Based on the product type, change the following text to anything wlse you like: Simple add to cart, Variable add to cart, Grouped add to cart, and External add to cart. And don’t remove the quotations, just change the text itself.

How to add custom code to your WordPress website

There are several ways to add custom code to your WordPress website. The most common method is to add the code to your website’s child theme. You can also use a free plugin for that.

Add the code to a child theme

Here are the general steps you would take to add custom code to your WordPress website:

  1. Access your website’s files: To add custom code to your website, you will need to access your website’s files. You can do this by using a file transfer protocol (FTP) client such as FileZilla or by accessing your website’s files through your web hosting control panel.
  2. Locate the functions.php file: Once you have access to your website’s files, you will need to locate the functions.php file. This file is usually located in the child theme folder, which is inside the wp-content/themes directory.
  3. Add the custom code: Once you have located the functions.php file, you can open it using a text editor and add your custom code to the end of the file. Make sure to add the code outside of any existing function in the file and wrap the code in php tags.
  4. Save and upload the file: After adding the custom code, save the functions.php file and upload it back to your website. Be sure to keep a copy of the original file, just in case you need to revert the changes.
  5. Check the website: Visit your website to make sure that the custom code has been added correctly and that it is functioning as expected.

Add the code using a plugin

Code Snippets is a lightweight and easy-to-use plugin that allows you to run custom code snippets on your WordPress website. With Code Snippets, you no longer have to manually add code to your theme’s functions.php file, which can be difficult for a lot of users to manage. Instead, it provides an intuitive and user-friendly interface to create, manage and organize code snippets.

That’s it! I hope this post was helpful and easy to follow. If you have any questions or the code stopped working, please, let me know in the comments below.

By Abdou

My name is Abdelfatah Aboelghit, a PHP developer from Egypt and my friends call me Abdou!
Here I write and develop products about Divi Theme.

More Article


Submit a Comment

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

All Access Bundle

Get ALL current & future products for $69/year instead of $327/year

Save Now →

Download The Most Powerful WordPress Theme

Pin It on Pinterest

Share This