If this is_product_category()
is not working then you should get the current post and the next step getting the name or slug, Choose category name
$product_cat_name = $term->name;
and slug $product_cat_slug = $term->slug;
Category name example
/*Write here your own functions */
add_action('woocommerce_before_add_to_cart_button', 'ddd_above_add_to_cart', 100);
function ddd_above_add_to_cart() {
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
$nterms = get_the_terms( $post->ID, 'product_tag' );
foreach ($terms as $term ) {
$product_cat_id = $term->term_id;
$product_cat_name = $term->name;
break;
}
//compare current category name == any category name you want
if($product_cat_name =='vss' ) {
echo "This Work";
}
}
Category slug example
/*Write here your own functions */
add_action('woocommerce_before_add_to_cart_button', 'ddd_above_add_to_cart', 100);
function ddd_above_add_to_cart() {
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
$nterms = get_the_terms( $post->ID, 'product_tag' );
foreach ($terms as $term ) {
$product_cat_id = $term->term_id;
$product_cat_name = $term->name;
$product_cat_slug = $term->slug;
break;
}
//compare current category slug == any category slug you want
if($product_cat_slug =='any-slug-category' ) {
echo "This Work";
}
}