Rename The “Add to Cart” Button Label – Custom Text for Shop Buttons

Intermediate
✓ Tested
📅 August 23, 2025
⬇️ 0 Downloads
📋 2 Copies

This comprehensive code snippet allows you to completely customize the “Add to Cart” button text throughout your WooCommerce store. You can set different button labels based on product type, category, price, stock level, user role, season, and more.

What does this code do?

Instead of the generic “Add to Cart” text, this snippet lets you display contextual, engaging button text that better describes the action or creates urgency. It works on both shop/archive pages and single product pages.

Customization Options Included:

  • Product Type Based: Different text for simple, variable, grouped, and external products
  • Category Specific: Custom text for products in specific categories (courses, services, downloads)
  • Price Based: Different messages for free, budget, or premium products
  • Sale Products: Special text showing discount percentage for items on sale
  • Stock Levels: Urgency text when stock is low (“Only 3 Left – Buy Now!”)
  • Seasonal/Holiday: Automatic holiday-themed buttons (Black Friday, Christmas, etc.)
  • User Role Based: Different text for wholesale customers, VIP members, or first-time buyers
  • Cart Status: Shows “✓ In Cart” if product is already added

Default Button Texts (Easily Customizable):

  • Simple Products: “Buy Now”
  • Variable Products: “Choose Options”
  • Grouped Products: “View Products”
  • External Products: “Buy at Store”
  • Out of Stock: “Out of Stock”
  • Free Products: “Get for Free”
  • Sale Products: “Buy on Sale!”
  • Low Stock: “Only X Left – Buy Now!”

Smart Features:

  • Automatically detects product conditions and shows appropriate text
  • Priority system ensures most relevant text is displayed
  • Works with AJAX add to cart functionality
  • Fully translatable for multilingual sites
  • Includes shortcode for custom button placement

Example Use Cases:

  • Digital Products: “Download Now” instead of “Add to Cart”
  • Courses: “Enroll Now” for educational products
  • Services: “Book Service” for appointment-based products
  • Limited Stock: “Only 2 Left!” to create urgency
  • Seasonal: “Order for Christmas!” during holiday season

Shortcode Usage:

[tpsc_custom_add_to_cart id=”123″ text=”Custom Text” class=”my-button-class”]

⚠️ Important Warnings

⚠️ Always backup before modifying functions.php
⚠️ Some themes override WooCommerce button text - this code has high priority but conflicts are possible
⚠️ Category slugs must match exactly - check spelling and hyphens
⚠️ Price comparisons use base price, not including taxes
⚠️ Stock-based text only works for products with stock management enabled
⚠️ Seasonal text uses server timezone - adjust dates for your timezone
⚠️ User role detection requires exact role names (case-sensitive)
⚠️ Variable products show same text for all variations
⚠️ Some page builders might cache button text - clear cache after changes
⚠️ The "In Cart" detection might not work with some cart plugins
⚠️ External/Affiliate products might have different button behavior
💻 PHP Code
/**
 * Rename/Customize the "Add to Cart" button text throughout WooCommerce
 * Change button labels based on product type, category, or custom conditions
 * Prefix: tpsc_ (TP Snippet Collection)
 */

// ============================================
// CONFIGURATION - Set your custom text here
// ============================================

// Default button texts for different product types
define('TPSC_SIMPLE_PRODUCT_TEXT', 'Buy Now');           // Simple products
define('TPSC_VARIABLE_PRODUCT_TEXT', 'Choose Options');   // Variable products
define('TPSC_GROUPED_PRODUCT_TEXT', 'View Products');     // Grouped products
define('TPSC_EXTERNAL_PRODUCT_TEXT', 'Buy at Store');     // External/Affiliate products
define('TPSC_OUT_OF_STOCK_TEXT', 'Out of Stock');        // Out of stock products
define('TPSC_DEFAULT_TEXT', 'Add to Cart');              // Fallback text

// ============================================
// SHOP/ARCHIVE PAGES - Button text
// ============================================

// Change button text on shop/archive pages
add_filter('woocommerce_product_add_to_cart_text', 'tpsc_custom_shop_button_text', 10, 2);

function tpsc_custom_shop_button_text($text, $product) {
    
    // Check if product is out of stock first
    if (!$product->is_in_stock()) {
        return __(TPSC_OUT_OF_STOCK_TEXT, 'woocommerce');
    }
    
    // Check product type and return appropriate text
    switch ($product->get_type()) {
        case 'simple':
            return __(TPSC_SIMPLE_PRODUCT_TEXT, 'woocommerce');
            
        case 'variable':
            return __(TPSC_VARIABLE_PRODUCT_TEXT, 'woocommerce');
            
        case 'grouped':
            return __(TPSC_GROUPED_PRODUCT_TEXT, 'woocommerce');
            
        case 'external':
            return __(TPSC_EXTERNAL_PRODUCT_TEXT, 'woocommerce');
            
        default:
            return __(TPSC_DEFAULT_TEXT, 'woocommerce');
    }
}

// ============================================
// SINGLE PRODUCT PAGE - Button text
// ============================================

// Change button text on single product pages - Simple & External products
add_filter('woocommerce_product_single_add_to_cart_text', 'tpsc_custom_single_button_text', 10, 2);

function tpsc_custom_single_button_text($text, $product) {
    
    // Check if product is out of stock
    if (!$product->is_in_stock()) {
        return __(TPSC_OUT_OF_STOCK_TEXT, 'woocommerce');
    }
    
    // Return text based on product type
    if ($product->is_type('simple')) {
        return __(TPSC_SIMPLE_PRODUCT_TEXT, 'woocommerce');
    } elseif ($product->is_type('external')) {
        return __(TPSC_EXTERNAL_PRODUCT_TEXT, 'woocommerce');
    }
    
    return $text;
}

// ============================================
// ADVANCED: Category-specific button text
// ============================================

add_filter('woocommerce_product_add_to_cart_text', 'tpsc_category_specific_button_text', 20, 2);
add_filter('woocommerce_product_single_add_to_cart_text', 'tpsc_category_specific_button_text', 20, 2);

function tpsc_category_specific_button_text($text, $product) {
    
    // CUSTOMIZE THESE RULES AS NEEDED
    // Example: Different text for specific categories
    
    // Digital products category
    if (has_term('digital-downloads', 'product_cat', $product->get_id())) {
        return __('Download Now', 'woocommerce');
    }
    
    // Courses category
    if (has_term('courses', 'product_cat', $product->get_id())) {
        return __('Enroll Now', 'woocommerce');
    }
    
    // Services category
    if (has_term('services', 'product_cat', $product->get_id())) {
        return __('Book Service', 'woocommerce');
    }
    
    // Membership category
    if (has_term('membership', 'product_cat', $product->get_id())) {
        return __('Join Now', 'woocommerce');
    }
    
    // Gift cards category
    if (has_term('gift-cards', 'product_cat', $product->get_id())) {
        return __('Purchase Gift Card', 'woocommerce');
    }
    
    return $text;
}

// ============================================
// PRICE-BASED: Different text based on price
// ============================================

add_filter('woocommerce_product_add_to_cart_text', 'tpsc_price_based_button_text', 30, 2);
add_filter('woocommerce_product_single_add_to_cart_text', 'tpsc_price_based_button_text', 30, 2);

function tpsc_price_based_button_text($text, $product) {
    
    // Skip if product doesn't have a price
    if (!$product->get_price()) {
        return $text;
    }
    
    $price = floatval($product->get_price());
    
    // Free products (price = 0)
    if ($price == 0) {
        return __('Get for Free', 'woocommerce');
    }
    
    // High-value products (over $500)
    if ($price > 500) {
        return __('Purchase Premium', 'woocommerce');
    }
    
    // Low-value products (under $10)
    if ($price < 10) {
        return __('Quick Buy', 'woocommerce');
    }
    
    return $text;
}

// ============================================
// SALE PRODUCTS: Special text for items on sale
// ============================================

add_filter('woocommerce_product_add_to_cart_text', 'tpsc_sale_button_text', 40, 2);
add_filter('woocommerce_product_single_add_to_cart_text', 'tpsc_sale_button_text', 40, 2);

function tpsc_sale_button_text($text, $product) {
    
    // Check if product is on sale
    if ($product->is_on_sale() && $product->is_in_stock()) {
        
        // Calculate discount percentage for more dynamic text
        if ($product->get_regular_price() && $product->get_sale_price()) {
            $percentage = round(100 - ($product->get_sale_price() / $product->get_regular_price() * 100));
            
            // High discount (over 50%)
            if ($percentage >= 50) {
                return sprintf(__('Save %d%% - Buy Now!', 'woocommerce'), $percentage);
            }
            // Regular sale
            else {
                return __('Buy on Sale!', 'woocommerce');
            }
        }
        
        return __('Special Offer - Buy Now', 'woocommerce');
    }
    
    return $text;
}

// ============================================
// STOCK-BASED: Different text based on stock levels
// ============================================

add_filter('woocommerce_product_add_to_cart_text', 'tpsc_stock_based_button_text', 50, 2);
add_filter('woocommerce_product_single_add_to_cart_text', 'tpsc_stock_based_button_text', 50, 2);

function tpsc_stock_based_button_text($text, $product) {
    
    // Only for products with stock management
    if ($product->managing_stock() && $product->is_in_stock()) {
        $stock_quantity = $product->get_stock_quantity();
        
        // Low stock (less than 5)
        if ($stock_quantity > 0 && $stock_quantity <= 5) {
            return sprintf(__('Only %d Left - Buy Now!', 'woocommerce'), $stock_quantity);
        }
        
        // Very low stock (only 1 left)
        if ($stock_quantity == 1) {
            return __('Last One - Grab It!', 'woocommerce');
        }
    }
    
    return $text;
}

// ============================================
// SEASONAL/TIME-BASED: Different text based on date/time
// ============================================

add_filter('woocommerce_product_add_to_cart_text', 'tpsc_seasonal_button_text', 60, 2);
add_filter('woocommerce_product_single_add_to_cart_text', 'tpsc_seasonal_button_text', 60, 2);

function tpsc_seasonal_button_text($text, $product) {
    
    // Get current date
    $current_month = date('n');
    $current_day = date('j');
    
    // Black Friday (November)
    if ($current_month == 11 && $current_day >= 24 && $current_day <= 30) {
        return __('Black Friday Deal!', 'woocommerce');
    }
    
    // Christmas season (December)
    if ($current_month == 12 && $current_day <= 25) {
        return __('Order for Christmas!', 'woocommerce');
    }
    
    // New Year (January)
    if ($current_month == 1 && $current_day <= 7) {
        return __('New Year Special!', 'woocommerce');
    }
    
    // Valentine's Day (February 1-14)
    if ($current_month == 2 && $current_day <= 14) {
        return __('Gift for Valentine!', 'woocommerce');
    }
    
    return $text;
}

// ============================================
// USER ROLE BASED: Different text for different users
// ============================================

add_filter('woocommerce_product_add_to_cart_text', 'tpsc_user_role_button_text', 70, 2);
add_filter('woocommerce_product_single_add_to_cart_text', 'tpsc_user_role_button_text', 70, 2);

function tpsc_user_role_button_text($text, $product) {
    
    // Check if user is logged in
    if (is_user_logged_in()) {
        $user = wp_get_current_user();
        
        // Wholesale customers
        if (in_array('wholesale_customer', $user->roles)) {
            return __('Wholesale Order', 'woocommerce');
        }
        
        // VIP members
        if (in_array('vip_member', $user->roles)) {
            return __('VIP Purchase', 'woocommerce');
        }
        
        // First-time buyers (no previous orders)
        $customer_orders = wc_get_orders([
            'customer_id' => $user->ID,
            'limit' => 1,
        ]);
        
        if (empty($customer_orders)) {
            return __('First Purchase - Buy Now!', 'woocommerce');
        }
    } else {
        // Not logged in users
        return __('Buy Now - Sign Up for Discount!', 'woocommerce');
    }
    
    return $text;
}

// ============================================
// AJAX ADD TO CART: Update button after adding
// ============================================

add_filter('woocommerce_product_add_to_cart_text', 'tpsc_ajax_added_to_cart_text', 80, 2);

function tpsc_ajax_added_to_cart_text($text, $product) {
    
    // Check if this product is already in cart
    if (tpsc_product_in_cart($product->get_id())) {
        return __('✓ In Cart - Add More?', 'woocommerce');
    }
    
    return $text;
}

// Helper function to check if product is in cart
function tpsc_product_in_cart($product_id) {
    if (!WC()->cart) {
        return false;
    }
    
    foreach (WC()->cart->get_cart() as $cart_item) {
        if ($cart_item['product_id'] == $product_id) {
            return true;
        }
    }
    
    return false;
}

// ============================================
// SHORTCODE: Display custom button anywhere
// ============================================

add_shortcode('tpsc_custom_add_to_cart', 'tpsc_custom_add_to_cart_shortcode');

function tpsc_custom_add_to_cart_shortcode($atts) {
    $atts = shortcode_atts([
        'id' => '',
        'text' => 'Add to Cart',
        'class' => 'button',
    ], $atts);
    
    if (empty($atts['id'])) {
        return '';
    }
    
    return sprintf(
        '<a href="%s" data-product_id="%s" class="add_to_cart_button ajax_add_to_cart %s">%s</a>',
        esc_url(wc_get_cart_url() . '?add-to-cart=' . $atts['id']),
        esc_attr($atts['id']),
        esc_attr($atts['class']),
        esc_html($atts['text'])
    );
}

📝 Installation Instructions

QUICK START:
1. Copy the entire code
2. The default texts are already set at the top of the code (lines 11-16)
3. Paste in functions.php or Code Snippets plugin
4. Save and check your shop page - buttons will immediately show new text!

CUSTOMIZING BASIC BUTTON TEXTS:
Find these lines at the top of the code (11-16):
- TPSC_SIMPLE_PRODUCT_TEXT: Text for regular products
- TPSC_VARIABLE_PRODUCT_TEXT: Text for products with variations
- TPSC_GROUPED_PRODUCT_TEXT: Text for grouped products
- TPSC_EXTERNAL_PRODUCT_TEXT: Text for affiliate/external products
- TPSC_OUT_OF_STOCK_TEXT: Text when product is out of stock
Change any of these to your preferred text

CATEGORY-SPECIFIC TEXT:
1. Find the function: tpsc_category_specific_button_text (line 82)
2. Look for example categories like 'digital-downloads', 'courses', etc.
3. Replace with your actual category slugs
4. Add more categories by copying the if statement pattern

TO FIND YOUR CATEGORY SLUGS:
1. Go to Products → Categories
2. Hover over a category and look at the URL
3. The slug appears after "tag_ID="

CUSTOMIZING PRICE-BASED TEXT:
Lines 119-137 contain price conditions:
- Free products (price = 0): "Get for Free"
- Premium (over $500): "Purchase Premium"
- Budget (under $10): "Quick Buy"
Adjust the price thresholds and text as needed

SEASONAL/HOLIDAY TEXT:
Lines 206-229 contain date-based conditions
Current holidays included:
- Black Friday (November 24-30)
- Christmas (December 1-25)
- New Year (January 1-7)
- Valentine's Day (February 1-14)
Add your own by copying the pattern

DISABLE SPECIFIC FEATURES:
To turn off any feature, comment out its add_filter line:
- Line 27: Basic product type text
- Line 82: Category-specific text
- Line 119: Price-based text
- Line 150: Sale product text
- Line 178: Stock-based text
- Line 206: Seasonal text
- Line 239: User role text

USER ROLE CUSTOMIZATION:
Lines 239-273 handle different user types
To add custom roles:
1. Find: if (in_array('wholesale_customer', $user->roles))
2. Replace 'wholesale_customer' with your role slug
3. Set appropriate button text

TESTING DIFFERENT SCENARIOS:
1. Set a product on sale - see sale-specific text
2. Set low stock (1-5 items) - see urgency text
3. Set product to $0 - see "Get for Free"
4. Log out - see visitor-specific text
5. Change date on computer - test seasonal text

USING THE SHORTCODE:
Place anywhere in pages/posts:
[tpsc_custom_add_to_cart id="99" text="Buy This Now"]
- id: Product ID (required)
- text: Button text (optional)
- class: CSS classes (optional)

📸 Screenshots