• Resolved oakwoodmedia

    (@oakwoodmedia)


    Good Morning World,

    I’m looking for some assistance if possible. I’m trying to hide the add to cart button (only button) for non logged in users however I do have a free sample button which links to this so every time I hide this it removes everything.

    I am using the Elementor builder and Hello Theme.

    I have tried:
    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 );

    —————————–

    .add_to_cart_button {
    display: none;
    }
    // Returns the add to cart button on the shop/category pages for logged in visitors
    .logged-in .add_to_cart_button {
    display: inline-block;
    }
    // Hides the add to cart button on the single product pages for all visitors
    .single_add_to_cart_button {
    display: none;
    }
    // Returns the add to cart button on the single product pages for logged in visitors
    .logged-in .single_add_to_cart_button {
    display: inline-block;
    }

    But not having much look, any help would be appreciated.

    Thanks in advance

Viewing 3 replies - 1 through 3 (of 3 total)
  • @oakwoodmedia

    Kindly try the code provided here using the code snippets plugin

    Thread Starter oakwoodmedia

    (@oakwoodmedia)

    Just to let everyone know that my original code was working however something in my theme was blocking it so added the !important string and all working

    /** Hides the add to cart button on the shop/category pages for all visitors
    */
    .add_to_cart_button { 
        display: none !important;
    }
    /** Returns the add to cart button on the shop/category pages for logged in visitors
    */
    .logged-in .add_to_cart_button {
        display: inline-block !important;
    }
    /** Hides the add to cart button on the single product pages for all visitors
    */
    .single_add_to_cart_button {
        display: none !important;
    }
    /** Returns the add to cart button on the single product pages for logged in visitors
    */
    .logged-in .single_add_to_cart_button {
        display: inline-block !important;
    }

    Awesome! Thanks for sharing your solution with the WooCommerce community.

    It’ll be helpful for others having a similar requirement.

    Feel free to create a new topic if you have any further questions.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hide Cart Button Only for non logged in users’ is closed to new replies.