// Specific product category archive and shop pages
add_action( 'woocommerce_after_shop_loop_item_title', 'hide_loop_product_prices', 1 );
function hide_loop_product_prices(){
global $product;
if (! is_user_logged_in()) {
if( is_product_category('services') || has_term( 'services', 'product_cat', $product->get_id() ) ){
// Hide prices
remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
// Hide add-to-cart button
remove_action('woocommerce_after_shop_loop_item','woocommerce_template_loop_add_to_cart', 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', 99 );
}
else
{
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
add_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
remove_action('woocommerce_single_product_summary', 'insight_print_register_to_see', 31);
remove_action('woocommerce_after_shop_loop_item','insight_print_register_to_see', 99 );
}
}
}
// Single product pages
add_action( 'woocommerce_single_product_summary', 'hide_single_product_prices', 1 );
function hide_single_product_prices(){
global $product;
if (! is_user_logged_in()) {
if(is_product_category('services') || has_term( 'services', 'product_cat', $product->get_id() ) ):
// Hide prices
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
// Hide add-to-cart button, quantity buttons (and attributes dorpdowns for variable products)
if( ! $product->is_type('variable') ){
remove_action('woocommerce_single_product_summary','woocommerce_template_single_add_to_cart', 30 );
} else {
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
}
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 );
endif;
}
}
function insight_print_register_to_see() {
echo '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '">' . __('Login/Register to see Price', 'theme_name') . '</a>';
}
// Specific product category archive and shop pages
add_action( 'woocommerce_after_shop_loop_item_title', 'hide_loop_product_prices', 1 );
function hide_loop_product_prices(){
global $product;
if (! is_user_logged_in()) {
if( is_product_category('services') || has_term( 'services', 'product_cat', $product->get_id() ) ){
// Hide prices
remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
// Hide add-to-cart button
remove_action('woocommerce_after_shop_loop_item','woocommerce_template_loop_add_to_cart', 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', 99 );
}
else
{
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
add_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
}
}
}
// Single product pages
add_action( 'woocommerce_single_product_summary', 'hide_single_product_prices', 1 );
function hide_single_product_prices(){
global $product;
if (! is_user_logged_in()) {
if(is_product_category('services') || has_term( 'services', 'product_cat', $product->get_id() ) ):
// Hide prices
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
// Hide add-to-cart button, quantity buttons (and attributes dorpdowns for variable products)
if( ! $product->is_type('variable') ){
remove_action('woocommerce_single_product_summary','woocommerce_template_single_add_to_cart', 30 );
} else {
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
}
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 );
endif;
}
}
function insight_print_register_to_see() {
echo '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '">' . __('Login/Register to see Price', 'theme_name') . '</a>';
}
// Specific product category archive and shop pages
add_action( 'woocommerce_after_shop_loop_item_title', 'hide_loop_product_prices', 1 );
function hide_loop_product_prices(){
global $product;
if (! is_user_logged_in()) {
if( is_product_category('services') || has_term( 'services', 'product_cat', $product->get_id() ) ){
// Hide prices
remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
// Hide add-to-cart button
remove_action('woocommerce_after_shop_loop_item','woocommerce_template_loop_add_to_cart', 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', 99 );
}
else
{
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
add_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
remove_action('woocommerce_single_product_summary', 'insight_print_register_to_see', 31);
remove_action('woocommerce_after_shop_loop_item','insight_print_register_to_see', 99 );
}
}
}
// Single product pages
add_action( 'woocommerce_single_product_summary', 'hide_single_product_prices', 1 );
function hide_single_product_prices(){
global $product;
if (! is_user_logged_in()) {
if(is_product_category('services') || has_term( 'services', 'product_cat', $product->get_id() ) ):
// Hide prices
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
// Hide add-to-cart button, quantity buttons (and attributes dorpdowns for variable products)
if( ! $product->is_type('variable') ){
remove_action('woocommerce_single_product_summary','woocommerce_template_single_add_to_cart', 30 );
} else {
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
}
add_action( 'woocommerce_single_product_summary', 'insight_print_register_to_see', 31 );
endif;
}
}
function insight_print_register_to_see() {
echo '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '">' . __('Login/Register to see Price', 'theme_name') . '</a>';
}
You can use below code to hide add to cart
& price
for WooCommerce products in the 'Services' category.
// Specific product category archive and shop pages
add_action( 'woocommerce_after_shop_loop_item_title', 'hide_loop_product_prices', 1 );
function hide_loop_product_prices(){
global $product;
if (! is_user_logged_in()) {
if( is_product_category('services') || has_term( 'services', 'product_cat', $product->get_id() ) ){
// Hide prices
remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
// Hide add-to-cart button
remove_action('woocommerce_after_shop_loop_item','woocommerce_template_loop_add_to_cart', 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', 99 );
}
else
{
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
add_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
}
}
}
// Single product pages
add_action( 'woocommerce_single_product_summary', 'hide_single_product_prices', 1 );
function hide_single_product_prices(){
global $product;
if (! is_user_logged_in()) {
if(is_product_category('services') || has_term( 'services', 'product_cat', $product->get_id() ) ):
// Hide prices
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
// Hide add-to-cart button, quantity buttons (and attributes dorpdowns for variable products)
if( ! $product->is_type('variable') ){
remove_action('woocommerce_single_product_summary','woocommerce_template_single_add_to_cart', 30 );
} else {
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
}
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 );
endif;
}
}
function insight_print_register_to_see() {
echo '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '">' . __('Login/Register to see Price', 'theme_name') . '</a>';
}
i have tested this code and working fine for me. let me know if this works for you.
lang-php