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!
PHP Snippet: Remove Add to Cart, Add View Product Button @ WooCommerce Shop
/**
* @snippet Remove Add Cart, Add View Product @ WooCommerce Loop
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @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>';
}
Thank a lot , your website help me manything π
have one question how can just remove star-rating too ?
Of course – just study the other Shop page hooks and you’ll find the solution
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
Astra customizes WooCommerce, hence some hooks or priorities may need to be adjusted
It works like a charm on the latest version of Woocommerce as of November 2022.
Great!
Thank you!
You’re welcome
Not sure this still works
It does. Can you test it on Storefront theme please?
Exactly what I needed Perfectly Working Thank You Sooooo Much.
Nice
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.
Cool. Screenshot please?
hey there! I put the snippet at functions.php but nothing happens
Can you try with a default theme?
Muito bom! Funcionou perfeitamente 15/09/2020.
Obrigado
Cool
Still works great! Thanks!
Fantastic
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!
Totally! Take a look at your add to cart buttons, see which classes they have, and add them to your “View Product” HTML.
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.
Cool!
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.
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!
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
Uhm yes I suppose you’d need to adapt the snippet to your theme code
Thank you very much! your code is working.
Great!
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.
Yes Amit, enable “Ajax add to cart” in the WooCommerce settings
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 }
End of everything, after } π
Hi Rodolfo!
Thanks a lot for this plugin! It works brilliantly! π
Great!
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
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!
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
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 π
Worked for me. Thank you so much!
Awesome π
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!
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 π
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.
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 π
Realmente nΓ£o estΓ‘ removendo o botΓ£o antigo =/
Mas funcionou perfeitamente mostrando o botΓ£o novo.
Try switching theme temporarily, does it work there?
Hello, it works great thanks !
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 !
Great π To remove that icon you probably need CSS.
works great many thanks simple 1 line of code
Excellent π
Hi Rodolfo,
the snippet works good but now all the buttons are in english…
Thanks Enrico! You have to edit the snippet slightly to change the button label π
Hi, this code crashed my site completelly.
Hey Raphael, thanks for your comment! I just tried it on Woo 3.1.1 and it worked ok – what error did you get?
Just added it to my Storefront theme and it works great.
Thank you
Brilliant π
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.
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 π
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.
Awesome!
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.
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
Rodolfo this is a great solution! works perfect! It’s possible to remove the add cart button from a specific product page?
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!
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.
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!
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
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!
You absolutely Rock! Thank you
Thanks a million Damien!
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 π
Ahah, excellent Rodrigo, thank you π
Nice one!
Much appreciated Conrad π