This topic has 4 replies, 3 voices, and was last updated 10 years, 2 months ago ago by Eva Kemp
Hi all, I’m facing a huge problem on Legenda theme. I have to remove the “Add to Cart” button from the single page for non logged in users. Usually I add the following code to functions.php (in this case we have to consider init.php inside Framework folder:
function members_only_price($price){
if(is_user_logged_in() ){
return $price;
}
else {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 10 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
}
}
add_action('init','members_only_price');
Unfortunately this doesn’t work for single product page, because the content-single-product.php have a single php instruction for “Add to Cart”:
`<?php woocommerce_template_single_add_to_cart(); ?>
How should I solve this issue? Thanks in advance for your replies.
Best Regards.
Hello,
You can try to copy content-single-product.php to Child Theme and wrap woocommerce_template_single_add_to_cart();
function into condition.
if(is_user_logged_in()){
}
Regards,
Jack Richardson
I did but it doesn’t work. Have you tested it in a local installation?
Hello,
Please try the solution described in this article: http://stackoverflow.com/questions/16509966/showing-add-to-cart-for-logged-in-users-only-woocommerce (the last answer).
Thank you.
Regards,
Eva Kemp.
The issue related to '‘Removing Add To Cart button’' has been successfully resolved, and the topic is now closed for further responses