Posted on

WooCommerce: Remove Add Cart, Add View Product @ Loop

A fan requested an interesting edit on the Shop/Category page (or “loop”). Instead of having the default “Add to Cart” button, they wanted to remove that and substitute with a “View Product” button link to the single product page. Here’s the simple snippet.

WooCommerce: Remove Add to Cart and add a View Product Button instead
WooCommerce: Remove Add to Cart and add a View Product Button instead

PHP Snippet: Remove Add to Cart, Add View Product Button @ WooCommerce Loop


/**
 * @snippet       Remove Add Cart, Add View Product @ WooCommerce Loop
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @sourcecode    https://businessbloomer.com/?p=20721
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.1.1
 */

// First, remove Add to Cart Button

remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );

// Second, add View Product Button

add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_view_product_button', 10);

function bbloomer_view_product_button() {
global $product;
$link = $product->get_permalink();
echo '<a href="' . $link . '" class="button addtocartbutton">View Product</a>';
}

Where to add this code?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such delicate files - if you need more guidance, please take a look at my free WooCommerce Customization video tutorial.

Does this snippet still work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free videos, tutorials and tips!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP
  • woocommerce-customize-shop-page-PHP
  • woocommerce-advanced-customization
  • how-to-edit-woocommerce-cart
  • woocommerce-customize-checkout-page-PHP
  • woocommerce-email-customization
  • woocommerce-conditional-logic

Rodolfo Melogli

Author, WooCommerce expert, WordCamp speaker and Internet marketer, Rodolfo Melogli has worked as a WooCommerce freelancer since 2011. He helps entrepreneurs and developers overcome their WooCommerce nightmares :) Rodolfo is the organiser of WordCamp Dublin, the Dublin WooCommerce Meetup, the Dublin Ecommerce Meetup and the Dublin WordPress Meetup. He enjoys interacting with people, travelling and chasing tennis & soccer balls. Of course, he loves pizza too.

35 thoughts on “WooCommerce: Remove Add Cart, Add View Product @ Loop

  1. Worked for me. Thank you so much!

    1. Awesome ๐Ÿ™‚

  2. This sounds like the perfect solution but I am not sure how to translate the code to css. I tried creating a child theme, but it was too complex with my parent theme’s design. I am hoping modifying the css will work instead as that is much easier to do. I got the remove button css from the comments. I don’t have the view product text.
    Thanks!

    1. Hey Neely, thanks for your comment! Unfortunately you can’t achieve this with simple CSS, and PHP is a more efficient way to do it anyway ๐Ÿ™‚

  3. Hmm… The new button appears but for some reason the old one won’t go away. I have two buttons appearing!

    Now, I can see that:

    remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’, 10 );

    is definitely included in my code snippet. Maybe there is a plugin interfering?

    Anyway, I have removed the botton using:

    .add_to_cart_button{display:none !important;}

    in the CSS.

    1. Hey John, thanks for your comment! Yes, it could be your theme or another plugin is already removing that bit, and re-adding it under a different function. You’ll therefore need to remove this custom function and not the default one ๐Ÿ™‚

  4. Hello, it works great thanks !

    1. Only one question : I have an icon showing on the button when “hover”. Do you have any idea how to remove this icon?
      Thank you very much in advance for your help !

    2. Great ๐Ÿ™‚ To remove that icon you probably need CSS.

  5. works great many thanks simple 1 line of code

    1. Excellent ๐Ÿ™‚

  6. Hi Rodolfo,

    the snippet works good but now all the buttons are in english…

    1. Thanks Enrico! You have to edit the snippet slightly to change the button label ๐Ÿ™‚

  7. Hi, this code crashed my site completelly.

    1. Hey Raphael, thanks for your comment! I just tried it on Woo 3.1.1 and it worked ok – what error did you get?

    2. Just added it to my Storefront theme and it works great.
      Thank you

  8. Hi, I have added it, but it doesn’t remove the Add to Cart button. Only added the View Product button.
    Please is possible to help me and tell me if it will also remove the button from all other places where it will be shown?

    Thanks.

    1. Alfista, thanks for your comment! That’s probably because of your theme, which is customizing the Add to Cart PHP. Sorry but I can’t help here and without studying your theme code ๐Ÿ™‚

  9. Worked perfectly! I have both Variable products and Simple products in my Categories. I didn’t like that the variable items button was ‘Select Options’ and the simple items button was ‘Add to Cart’. Great solution to make them all the same label AND the same action. Thanks Rodolfo.

  10. Hello!

    How to you remove the view details button while hovering the mouse over the product image in category view? I googled it and added some codes in Theme options -> Custom CSS but without any result.

    1. Hey Bogdan, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R

  11. Rodolfo this is a great solution! works perfect! It’s possible to remove the add cart button from a specific product page?

    1. Hola Lucas, thanks for your comment! All you need to add in this case is a “conditional tag” – watch this tutorial https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and read this guide https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/ to get an idea. Hope this helps!

  12. Hi…. I have probed the code, and it works properly to add button “View Product”, but it don’t works for remove button “Add Cart”.

    Any suggestion?

    Best regards.

    1. Javi, thanks for your comment! Probably your theme is overriding the Add to Cart functionality, and therefore you’ll need to investigate this through the theme code. My snippet works for default WooCommerce – let me know if you find a fix!

  13. Rodrigo ciao,
    The Remove Add to Cart, Add View Product Button @ WooCommerce Loop work fine on the shop page.
    What is the correct PHP snippet to remove “Add to Chart” and add “View Product” in every page of the website not just only the shop page?
    Single product page can stay as it is “Add to Chart” button.

    Thank you

    1. Hey Iarp, thanks for your comment! I guess by “any page” you mean “non-WooCommerce” pages, and I also guess you use some sort of visual builder. If that is the case, this is custom to the shortcodes you’re using on that given page – my snippet is for a default WooCommerce install. Hope this helps!

  14. You absolutely Rock! Thank you

    1. Thanks a million Damien!

  15. Nice one. It took me a good day to find this solution last week from a different forum. Hope I was not the fan, since I can’t remember if I commented about this in your site ๐Ÿ™‚

    1. Ahah, excellent Rodrigo, thank you ๐Ÿ™‚

  16. Nice one!

    1. Much appreciated Conrad ๐Ÿ™‚

Questions? Feedback? Support? Leave your Comment Now!
If you're writing code, please wrap it between: [php] code_here [/php]

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.