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 Loop

/**
 * @snippet       Remove Add Cart, Add View Product @ WooCommerce Loop
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 3.6.2
 * @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 (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 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+.

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

Check out these free video tutorials. You can start learning how to customize WooCommerce without unnecessary plugins. Watch me code and learn by example!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a 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.

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

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

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

    1. Great!

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

  4. 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 } ๐Ÿ™‚

  5. Hi Rodolfo!

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

    1. Great!

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

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

  8. Worked for me. Thank you so much!

    1. Awesome ๐Ÿ™‚

  9. 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 ๐Ÿ™‚

  10. 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 ๐Ÿ™‚

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

  12. works great many thanks simple 1 line of code

  13. 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 ๐Ÿ™‚

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

  15. 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 ๐Ÿ™‚

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

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

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

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

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

  21. You absolutely Rock! Thank you

    1. Thanks a million Damien!

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

  23. Nice one!

    1. Much appreciated Conrad ๐Ÿ™‚

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

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

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