• Resolved iamrahul95

    (@iamrahul95)


    Hi,
    I have a fresh woo commerce installation with the storefront theme. Created a child theme for it and i want to remove the add to cart button from the site for non-logged in users. I have used this snippet

    
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
        remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
        remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
        remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
    

    which have actually removed the button from the shop page and product-details page. But it is still visible on the home page under New arrival, Best Sellers, On sale and Favourites sections. Is there any way to remove the same from these sections also ? I don’t prefer hiding it using css as it seems kind of a hack. Is there any filters available for it, or through template overriding. I followed this documentation but had no scope at all. (https://docs.woocommerce.com/document/storefront-hooks-actions-filters/)

    Could anyone please help me with this ?

Viewing 5 replies - 1 through 5 (of 5 total)
  • I plugged your code into the default Storefront functions.php file and it removed the Add to Cart button on the front page of my local install. My frontpage is set to use the Homepage template so maybe yours doesn’t use that and you’re using blocks?

    Hi @iamrahul95,

    Like Jarret said would you happen to be using product blocks in your homepage? There may be a different way to then remove the add to cart button from blocks on the homepage.

    At the moment the actions you’re removing don’t apply to blocks. 🙂

    Thread Starter iamrahul95

    (@iamrahul95)

    My home page too is set to the static Home Page template.

    Hi @iamrahul95,

    So would a filter like the one below work?

    add_filter( 'woocommerce_is_purchasable', '__return_false');

    This disables any purchasing, but then you would still see buttons that say “Read more.”

    remove Add to Cart buttons
    Link to image: https://cld.wthms.co/BEqkpV

    Thread Starter iamrahul95

    (@iamrahul95)

    Hi, @ryanr14 It actually worked. Thank you ! The Read More button is not a problem, it was the cart button and checkout that bothered me. Once again, thank you!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Remove Add to Cart Button from storeront’ is closed to new replies.