WooCommerce: Remove Add Cart, Add View Product @ Shop Page

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 – enjoy!

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 Shop

/**
 * @snippet       Remove Add Cart, Add View Product @ WooCommerce Loop
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
// 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 snippet?

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

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.3.

If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

73 thoughts on “WooCommerce: Remove Add Cart, Add View Product @ Shop Page

  1. It works like a charm on the latest version of Woocommerce as of November 2022.

  2. Thank you!

  3. Not sure this still works

    1. It does. Can you test it on Storefront theme please?

  4. Exactly what I needed Perfectly Working Thank You Sooooo Much.

  5. Hey there, thanks for this! I had to try quite a few, glad I found this one that finally works! One small issue is that I now have two ‘buy product’ buttons on the full item listing? Please let me know if you have any ideas how I can resolve this.

    1. Cool. Screenshot please?

  6. hey there! I put the snippet at functions.php but nothing happens

    1. Can you try with a default theme?

  7. Muito bom! Funcionou perfeitamente 15/09/2020.
    Obrigado

    1. Cool

  8. Still works great! Thanks!

    1. Fantastic

  9. This works great, however my button is not styled at all. Is there a way to import the styling from the template so that it matches the existing ‘add to cart button’ and changes with changes int he adimin?

    Many thanks!

    1. Totally! Take a look at your add to cart buttons, see which classes they have, and add them to your “View Product” HTML.

  10. I want to apply this method to one of my clients. I’m hoping this will help with SEO for my archive pages by cleaning up the URLs. Either way, the real reason I’m implementing is because when I use Screaming Frog to crawl the site it returns duplicate URLs and while there is a way to filter those out, I don’t know how and this seems to be the easier solution.

    One other benefit is getting customers to go to additional pages. I know this is not necessarily a win-win because I also want it to be easy for the customer to add products to their cart.

    One final thought, I think I’m going to wait until after the release of WooCommerce 4 so that in case there are bugs hopefully I can avoid them.

    Thanks as always for the useful resources.

    1. Cool!

  11. Just what I’ve been looking for but for only one/two specific categories rather than all categories.
    Can the code above be modified to target just these categories? The only other option is to remove the button completely and hope the visitor will click the image/product name.

    1. Hi Rob, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  12. In my case it doesn’t work as I am already using a child theme (so I have to edit the theme functions and I can not create a cgrandchild theme https://stackoverflow.com/questions/46913744/wordpress-child-theme-of-a-child-theme ) Also my theme is Arcanum ( a child of esotera) and this one has a hoverable add to cart so in my case View product appears as it should but also add to cart appearrs hoverable in the middle of the product as it used to be.Though I guess it will still work for most people good job

    1. Uhm yes I suppose you’d need to adapt the snippet to your theme code

  13. Thank you very much! your code is working.

    1. Great!

  14. I was using this snippet till now, worked great.

    I have a situation, is it possible to show only “View Cart” button on single product page once a user clicks on “Add to Cart”.

    Thanks for all the help.

    1. Yes Amit, enable “Ajax add to cart” in the WooCommerce settings

  15. Tell me if i understand this correctly, if in my functions.php I have something like that…
    I should add your snippet before <?php or at the end of everything after }

    1. End of everything, after } πŸ™‚

  16. Hi Rodolfo!

    Thanks a lot for this plugin! It works brilliantly! πŸ™‚

    1. Great!

  17. Since we may or may not use multilang its good practice when you make some functionalities that are using same strings such as View product to be translation ready

    1. Sorry Snuffy but I disagree with you πŸ™‚ My snippets are not premium plugins so I don’t have the time to follow good practices all the time. Thanks for your feedback anyway!

  18. Hi Rodolfo,

    Great little script and works perfectly. I’ve just used it on one of my clients sites.

    Just one question. Is it possible to add to this so just one category shows “Join Us Now” instead of “View Product”?

    Thanks,

    Tassie

    1. Thanks Tassie! Yes, I suggest you take a look at “conditional logic”: https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know πŸ™‚

  19. Worked for me. Thank you so much!

    1. Awesome πŸ™‚

  20. 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 πŸ™‚

  21. 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 πŸ™‚

      1. Realmente nΓ£o estΓ‘ removendo o botΓ£o antigo =/
        Mas funcionou perfeitamente mostrando o botΓ£o novo.

        1. Try switching theme temporarily, does it work there?

  22. 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 !

      1. Great πŸ™‚ To remove that icon you probably need CSS.

  23. works great many thanks simple 1 line of code

  24. 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 πŸ™‚

  25. 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

  26. 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 πŸ™‚

  27. 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.

  28. 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

  29. 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!

  30. 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!

  31. 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!

  32. You absolutely Rock! Thank you

    1. Thanks a million Damien!

  33. 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 πŸ™‚

  34. Nice one!

    1. Much appreciated Conrad πŸ™‚

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

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