WooCommerce category specific add to cart button text

If I have a Woo-Commerce product category titled ATV how would I go about changing the add to cart button text on just that category?

I found the documentation here of how to change the text on the add to cart button but this appears to be for specific product types not categories.

Read More

Anybody have a solution?

Related posts

2 comments

  1. Use conditional logic. In this specifically, the function has_term()

    add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' );    // 2.1 +
    
    function woo_custom_cart_button_text( $text ) {
        if( has_term( 'your-special-category', 'product_cat' ) ){
            $text = __( 'My Button Text', 'your-plugin' );
        }
        return $text;
    }
    
  2. add_filter( 'woocommerce_product_add_to_cart_text', 'saan_archive_custom_cart_button_text' );
    function saan_archive_custom_cart_button_text() {
    global $product;
    $terms = get_the_terms( $product->ID, 'product_cat' );
    foreach ($terms as $term) {
    $product_cat = $term->name;
    break;
    }
    
    switch($product_cat){
    case 'category1'; return 'Category 1 button text'; break;
    case 'category2'; return 'Category 2 button text'; break;
    //case .....
    default; return 'Add to cart'; break;
    }
    }
    

    Try this code once. Don’t need to thank me..

Comments are closed.