• I cant quite get this to work.

    I want to change the add to cart text per category, so if a product is in category 393 show “go to” instead of add to cart.

    So far i have come come close with this.

    add_filter( 'add_to_cart_text', 'woo_custom_cart_button_text' );
    add_filter( 'woocommerce_product_add_to_cart_text', 'woo_custom_cart_button_text' );
    add_filter('woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text');
    
    function woo_custom_cart_button_text() {
     global $post;
    	$terms = get_the_terms( $post->ID, 'product_cat' );
    	if ( array_key_exists( 393, $terms ) ) {
            	return __( 'Yes! I WANT this!', 'your-slug' );
    	} else {
            return __( 'Add to Cart', 'woocommerce' );
    }
    
    }

    Any help is appreciated

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Woocommerce function add to cart text’ is closed to new replies.