Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

nat@cry on "WooCommerce Different text for add to cart depending on product category"

$
0
0

Right so the scene!

Would like a different text to appear on the add to cart button.

If is in category 'Donation' use custom text of donation
But for the rest of the products display other custom text "Add"

This is my code so far,

add_filter( 'add_to_cart_text', 'woo_custom_cart_button_text' );                                // < 2.1
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' );    // 2.1 +

function woo_custom_cart_button_text() {
	if(is_product_category('Donation')) {
	return __('Donate', 'woocommerce' );
  } else {
	  return __('Add', 'woocommerce' );
  }
}

Viewing all articles
Browse latest Browse all 8245

Trending Articles