I'd like to hide the "add to cart" & price for WooCommerce products in the 'Services' category.
I've tried the following code in my child theme's functions.php, but https://pureblissmoonhealer.com/product-category/services/ still displays "add to cart" & price.
Help appreciated.
function insight_hide_price_add_cart_not_logged_in() {
if (! is_user_logged_in()) {
if (is_product_category('Services')) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
add_action( 'woocommerce_single_product_summary', 'insight_print_register_to_see', 31 );
add_action( 'woocommerce_after_shop_loop_item', 'insight_print_register_to_see', 11 );
}
}
}
function insight_print_register_to_see() {
echo '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '">' . __('Register to see prices', 'theme_name') . '</a>';
}
add_action( 'init', 'insight_hide_price_add_cart_not_logged_in' );
init
hook is too early foris_product_category()
. Trywp
or a later hook.