Back to Blog

WooCommerce Snippet: Edit the WooCommerce button text for all product types

See how to easily edit the WooCommerce button text for the different product types offered with WooCommerce.


WooCustomizer: Edit the WooCommerce button text

WooCommerce comes with 3 different product types you can set up, they are Simple Products, Variable Products and Grouped Products, and with each, we’ll show you how to edit the WooCommerce button text which is displayed on each button type.

WooCommerce also offers the ability to set up external products, but for that product type you’re able to set the button text within the product page settings, so for the external button we will simply return the value saved in the product setting.

Edit the WooCommerce button text on Shop Pages:

Editing the WooCommerce product text is pretty simple, it just requires a check of the product type, and then according to the product type, you then return the different text you want on each button.

Copy and paste the code below to edit the WooCommerce button text on the WooCommerce shop and category list pages, and add it to your child theme or Site Customization plugin.

// Change button text on WooCommerce Shop pages
add_filter( 'woocommerce_product_add_to_cart_text', 'woocustomizer_edit_shop_button_text' );

function woocustomizer_edit_shop_button_text() {
    global $product;
    $product_type = $product->get_type(); // Get the Product Type
	
    // Change text depending on Product type
    switch ( $product_type ) {
        case "variable":
            return __( 'See Variations', 'woocommerce' );
            break;
        case "grouped":
            return __( 'View All Products', 'woocommerce' );
            break;
        case "external":
            // Button label is added when editing the product
            return esc_html( $product->get_button_text() );
            break;
        default:
            return __( 'Buy Now', 'woocommerce' );
    }
}

Edit the WooCommerce button text on the Product Page:

To edit the WooCommerce button text on the product single page is just as simple, simply copy and paste the code below and add it to your child theme or Site Customization plugin.

Change the return value to what you would like the button text to be.

// Change button text on WooCommerce product single page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_edit_product_single_button_text' );

function woocommerce_edit_product_single_button_text() {
    return __( 'Purchase Now', 'woocommerce' );
}

Our StoreCustomizer plugin offers these code snippets all built into the WordPress Customizer to easily edit the button text for each WooCommerce product type.