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
 * @community     https://businessbloomer.com/club/
 */
 
// 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 custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Custom Add to Cart URLs – The Ultimate Guide
    In WooCommerce you can add a product to the cart via a custom link. You just need to use the “add-to-cart” URL parameter followed by the product ID. This tutorial will show you how to create custom URLs to add simple, variable and grouped products to the cart – as well as defining the add […]
  • WooCommerce: Disable Variable Product Price Range $$$-$$$
    You may want to disable the WooCommerce variable product price range which usually looks like $100-$999 when variations have different prices (min $100 and max $999 in this case). With this snippet you will be able to hide the highest price, and add a “From: ” prefix in front of the minimum price. At the […]
  • WooCommerce: Hide Price & Add to Cart for Logged Out Users
    You may want to force users to login in order to see prices and add products to cart. That means you must hide add to cart buttons and prices on the Shop and Single Product pages when a user is logged out. All you need is pasting the following code in your functions.php (please note: […]
  • WooCommerce Visual Hook Guide: Archive / Shop / Cat Pages
    I’ve created a visual HTML hook guide for the WooCommerce Archive Page (which is the same page for the Shop, Category, Tag pages). This visual guide belongs to my “Visual Hook Guide Series“, that I’ve put together so that you can find WooCommerce hooks quickly and easily by seeing their actual locations (and you can […]
  • WooCommerce: Hide Prices on the Shop & Category Pages
    Interesting WooCommerce customization here. A client of mine asked me to hide/remove prices from the shop page and category pages as she wanted to drive more customers to the single product pages (i.e. increasing the click-through rate). As usual, a simple PHP snippet does the trick. I never recommend to use CSS to “hide” prices, […]

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. Follow @rmelogli

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

  1. Thank a lot , your website help me manything πŸ™‚

    have one question how can just remove star-rating too ?

    1. Of course – just study the other Shop page hooks and you’ll find the solution

  2. Did try this code in my old theme it works well but since I have switched to the Astra the button is placing above the title and the price not at the bottom

    1. Astra customizes WooCommerce, hence some hooks or priorities may need to be adjusted

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

  4. Thank you!

  5. Not sure this still works

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

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

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

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

    1. Can you try with a default theme?

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

    1. Cool

  10. Still works great! Thanks!

    1. Fantastic

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

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

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

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

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

    1. Great!

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

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

  18. Hi Rodolfo!

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

    1. Great!

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

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

  21. Worked for me. Thank you so much!

    1. Awesome πŸ™‚

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

  23. 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?

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

  25. works great many thanks simple 1 line of code

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

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

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

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

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

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

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

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

  34. You absolutely Rock! Thank you

    1. Thanks a million Damien!

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

  36. Nice one!

    1. Much appreciated Conrad πŸ™‚

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. 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 the Business Bloomer Club to get quick WooCommerce support. Thank you!

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