Reputation: 363
I have the following code that changes the button text of a variable product from 'select options' to select dates.
add_filter( 'woocommerce_product_add_to_cart_text', 'change_select_options_button_text', 9999, 2 );
function change_select_options_button_text( $label, $product ) {
if ( $product->is_type( 'variable' ) ) {
return 'Select Dates';
}
return $label;
}
I'm wanting to apply this only to a certain category instead of it applying to every variable product. Would this be possible?
I've tried adding : if ( is_product_category('cat1')
like so but have had no luck.
add_filter( 'woocommerce_product_add_to_cart_text', 'change_select_options_button_text', 9999, 2 );
function change_select_options_button_text( $label, $product ) {
if ( is_product_category('cat1') && $product->is_type( 'variable' ) ) {
return 'Select Dates';
}
return $label;
}
Any help would be greatly appreciated. Thank You!
Upvotes: 1
Views: 580
Reputation: 11861
add_filter('woocommerce_product_add_to_cart_text', 'change_select_options_button_text', 9999, 2);
function change_select_options_button_text($label, $product) {
if ($product->is_type('variable') && has_term(array('kids clothing'), 'product_cat', $product->get_id())) {
// Do something if the product is variable and in category "kids clothing"
return 'Select Dates';
}
return $label;
}
Upvotes: 1