Ask your WordPress questions! Pay money and get answers fast! (more info)

Woocommerce: Hide Prices & Add to Cart on ALL but Promotions page WordPress

Woocommerce: I'm using this code to Hide Price & 'Add to Cart' unless user is logged in & it works fine

Problem is I have a Promotions page which is the opening page & I would like display Promtion price but not add to cart

<blockquote>// Hide prices & add to cart if NOT logged in
add_action('after_setup_theme','activate_filter') ;
function activate_filter(){
add_filter('woocommerce_get_price_html', 'show_price_logged');
}
function show_price_logged($price){
if(is_user_logged_in() ){
return $price;
}
else
{
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
return '<a href="' . get_permalink(woocommerce_get_page_id('myaccount')) . '">' . __('<font color="red">Login to see prices</font>', 'theme_name') . '</a>';
}
}</blockquote>

Code also found here:

http://www.templatemonster.com/help/woocommerce-how-to-hide-prices-and-add-to-cart-for-unregistered-users.html#gref

I want to modify this so that if its a specific page ie. "Promotions" - in my case PageID 3739

I want to DISPLAY the prices on this page but still Hide add to Cart

Can anyone tell me how to modify or replace code to solve this problem?

Answers (1)

2016-04-29

Rempty answers:

Hello try with this code

add_action('after_setup_theme','activate_filter') ;
function activate_filter(){
add_filter('woocommerce_get_price_html', 'show_price_logged');
}
function show_price_logged($price){
if(is_user_logged_in() ){
return $price;
}
elseif(is_page(3739)){
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
return $price;
}
else
{
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
return '<a href="' . get_permalink(woocommerce_get_page_id('myaccount')) . '">' . __('<font color="red">Login to see prices</font>', 'theme_name') . '</a>';
}
}


bas mistry comments:

Thanks - that did it