Removing Add To Cart button - by Hoellwarth

This topic has 4 replies, 3 voices, and was last updated 10 years, 2 months ago ago by Eva Kemp

  • Avatar: Hoellwarth
    Hoellwarth
    Participant
    September 26, 2014 at 15:38

    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.

    3 Answers
    Avatar: Jack Richardson
    Jack Richardson
    Support staff
    September 26, 2014 at 17:54

    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

    Avatar: Hoellwarth
    Hoellwarth
    Participant
    September 27, 2014 at 22:07

    I did but it doesn’t work. Have you tested it in a local installation?

    Avatar: Eva
    Eva Kemp
    Support staff
    September 29, 2014 at 13:27

    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.

  • Viewing 4 results - 1 through 4 (of 4 total)

The issue related to '‘Removing Add To Cart button’' has been successfully resolved, and the topic is now closed for further responses

8theme customization service
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.