I would like to hide prices for products in specific categories, prices should be hidden only on shop and category page, but visible on product page, chart and subtotals.
Thank you!
This code has this functionality but I would like to apply it only on specific categories:
add_filter( 'woocommerce_after_shop_loop_item_title', 'remove_woocommerce_loop_price', 2 );
function remove_woocommerce_loop_price() {
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
}
3
Answers
You can get the cat name if you have the prodict id with the following:
So simply write a condition to the cat name
You can check if the product has a category by
has_term
function, and it’s an action hook not a filterTo hide the price based on specific product category slugs, you can use this:
To hide the price based on specific product category ids, you can use this:
The code has been tested and works. Add it to your theme’s functions.php.