Home / eCommerce / Change the “Add to Cart” Button Text
Duplicate Snippet

Embed Snippet on Your Site

Change the “Add to Cart” Button Text

Change Add to cart and Buy now buttons

Code Preview
php
<?php
/**
 * Change the "Add to Cart" button text globally.
 * Change 'Buy Now' to your desired text.
 */
function custom_woocommerce_product_add_to_cart_text( $text, $product ) {
    switch ( $product->get_type() ) {
        case 'external':
            return 'View Product'; // Or 'Buy from Vendor'
        case 'variable':
            return 'Select Options'; // Standard practice
        default:
            return 'Buy Now'; // Custom text for simple/other types
    }
    return $text;
}
add_filter( 'woocommerce_product_add_to_cart_text', 'custom_woocommerce_product_add_to_cart_text', 10, 2 );
// For the button on the main shop/archive page:
add_filter( 'woocommerce_product_loop_add_to_cart_link', function( $html, $product ) {
    if ( $product->is_type( 'simple' ) ) {
        // Change the text here for the shop page button
        $html = str_replace( 'Add to cart', 'Add to Bag', $html );
    }
    return $html;
}, 10, 2 );

Comments

Add a Comment