WooCommerce: Disable Link to Product @ Loop

Hello WooCommerce Customizers!

Episode #8 of my “18 snippets in 18 days” challenge (we have 10 days and 10 snippets to go) features a nice HTML hack.

Who doesn’t love hacks? 🙂

I remind you to share on social media and leave blog comments to support my marathon 🙂

Today we take a look at the WooCommerce Loop and specifically at how to disable the link to the products. Some store owner does not want to get people to the single product page, and simply have customers to add to cart!

WooCommerce: Disable Product Links on the Shop/Archive page
WooCommerce: Disable Product Links on the Shop/Archive page

WooCommerce Snippet: Disable Link to Products @ Loop

Thank you Daymobrew for your very elegant alternative to my initial hack 🙂 I love when 2 lines of code achieve a better result than 10!


/**
 * @snippet       Disable Link to Products @ Loop
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @sourcecode    https://businessbloomer.com/?p=19916
 * @author        Daymobrew
 * @testedwith    WooCommerce 2.6.4
 */

remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );

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

52 thoughts on “WooCommerce: Disable Link to Product @ Loop

  1. Hi Rodolfo!
    I need this only for one CATEGORY.
    thanks and regards from Milan

  2. Hello,
    Thank you for the code I was looking very useful !!
    I’m creating an affiliate site and would like to remove the existing link from the title as in your example and would like to add my affiliate link instead.
    Can you help me ?? How does one ??

    Thank you for your help

    1. Hello Aymeric, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  3. Works perfect! Woocommerce Version 3.5.4
    Thanks for that!

    1. Excellent!

  4. Hello
    Im new @ this
    I have a website that use woocomerce
    im adding products that link to amazon in different categories
    When i use the woocomerce shortcode to show the products in each categoty
    The product links first to the single product page then to amazon
    I want to link the product to amazon instead of going to my single product page
    how i would be able to change this

    1. Hi Robert, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  5. Works great, and used in conjunction with the CSS-Javascript-Toolbox plugin I can run this on selected pages.

    1. Excellent 🙂

  6. Still works great with WooCommerce 3.4.5 under WordPress 4.9.8. Thanks for the snippet.

    1. Excellent!

  7. Hi,

    Thank you, this works.
    BUT my product is set to allow only one per order.
    I also use AJAx to redirect to CART
    But when a user try to add a product already in the cart, it redirects to the single product page.

    Hope you can help.

    thank you.

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

  8. Hi Rodolfo,

    how would you go about making it so if it’s an external product, the link redirects to the external product instead of the internal page?

    Thank you

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

  9. Hi Rodolfo,
    I love your snippets and use them all the time!
    There is one snippet I wish for that is very similar to this one….
    I wish to disable links to products from the cart and the mini-cart.
    Hope you’ll get to it 2 soon

    1. Cheers Liran 🙂 Great, I will add this to my to-write list!

  10. For what it’s worth it didn’t work on WC 3, although I think template or custom category list was toy’d with…

    1. Hey Wilbur, thanks for your comment! It should work with Woo 3, therefore I believe your theme is overriding the default behaviors and changing the hooks/PHP 🙂

  11. Thanks for your post.. It really helped me!!

  12. Hi,
    I’m a beginner to actions and functions and am trying to reverse engineer this. My theme has a link on the thumbnail but not the title (on the archive page), how could I make the title also link?

    1. Hey Liam, thanks for your comment! You will need to take a look at your theme’s coding, as they’re likely overriding the WooCommerce default behaviour 🙂

  13. its awesome. worked for me but 1 issue. it disabled mouse wheel scrolling on that page.
    i can not scroll through mouse wheel after adding that code in my functions.php file

    1. Hello Ibtesam, thanks for your comment! I’m not sure your problem is related to my snippet, it’s just PHP and cannot affect the mouse wheel 🙂 Thank you, R

  14. Works like a charm, just dropped it in the theme’s function file and boom, worked flawlessly.
    Thanks a lot for the snippet.

    1. Thanks so much for your feedback Darwin!

  15. thank you so much …

    1. You’re welcome Mounish!

  16. Can someone help me how can I Disable Link to only SOLD Products? Thanks.

    1. Szabi, thanks so much for your comment! Did you mean the “Out of Stock” products?

    2. Yes. Adding the above code has removed the links from products.
      However, I want to target only on “out of stock” products or for a specific category (even better).

      Tried the following and didn’t work:

      function remove_direct_link_to_product_page() {
      if ( is_product_category( ‘category-slug’ ) ) {
      remove_action( ‘woocommerce_before_shop_loop_item’, ‘woocommerce_template_loop_product_link_open’, 10 );
      remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_product_link_close’, 5 );
      }
      }
      

      (I’ve probably got it coded wrong) any thoughts about this?

    3. Yes, indeed 🙂 You’re using a conditional tag that only works on the category page, and not the single product page. Try looking at https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/ to find the right tag. Let me know!

    4. Thanks a lot Rodolfo for your prompt reply, I’m still looking for the solution.

      Just to clarify I want the condition to work only on each product on the loop pages based on a category.

      The following code didn’t remove the product links under the category named ‘sold’, however, when I echoed something that was working…waiting for your answer, thanks.

      function remove_direct_link_to_product_page() {
      if ( has_term( 'sold', 'product_cat' ) ) {
      remove_action( ‘woocommerce_before_shop_loop_item’, ‘woocommerce_template_loop_product_link_open’, 10 );
      remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_product_link_close’, 5 );
      }
      }
      
    5. Your single quotes > ‘ are all over the place, but PHP would give you error I guess. When and how are you triggering the function “remove_direct_link_to_product_page”?

    6. Thanks again for your comment Rodolfo.
      I’ve corrected the quotes, however I’m not sure how I’m triggering the function :
      “remove_direct_link_to_product_page”
      I’ve actually just found this solution while I was browsing for hours.
      Still no success removing the links for products inside a category.

    7. That doesn’t seem to be my code, sorry but I can’t help 🙂

  17. Hi Rodolfo,

    i´ve got a question, is it possible to redirect the link from the image and text to the single product page to a external page?

    Thank you

    1. Hey TBone, thanks for your comment! Sure, of course there is a way to implement that on the single product page – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  18. How do I remove the product link from the cart page?

    1. Hey Ram, thanks for your comment! You can do so by using something similar to this: https://businessbloomer.com/woocommerce-remove-permalink-product-order-table. However, you’ll need to find the exact filter that is on the cart page, instead of the order page 🙂 Hope this helps!

  19. Using the default Twenty Sixteen theme would it be possible to do this only for external products or specific categories?

    1. Hey Syrehn, thanks so much for your comment! Of course this is possible, and it’s 100% independent from the theme you use. All you need is checking out this guide https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/ and you’ll be able to run this snippet only when a certain condition is met 🙂 Good luck!

  20. Sorry the silly question but where (file) I put this code? tks

    1. Erica, thanks for your comment! No question is ever silly 🙂

      You can place this in your child theme’s functions.php file – if you need more guidance, please take a look at this video tutorial: https://businessbloomer.com/woocommerce-customization-hangout/

      Let me know, ~R

  21. remove_action( ‘woocommerce_before_shop_loop_item’, ‘woocommerce_template_loop_product_link_open’, 10 );
    remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_product_link_close’, 5 );
    

    Does not seem to work for me…. 🙁

    Storefront child theme 2.1.2
    Woocommerce 2.6.4
    WP : 4.6.1

    any ideas ?

    1. Hey Marc, I just tested it with the exact same versions and the product image and product title links in the shop/category page are correctly disabled! You have to remove the Add to Cart as well, but those 2 remove_action work perfectly 🙂 Not sure!

    2. Got it !
      ‘ and not ‘

      remove_action(‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_product_link_close’, 5 );
      remove_action( ‘woocommerce_before_shop_loop_item’, ‘woocommerce_template_loop_product_link_open’, 10 );

    3. Ahah excellent! Yes, those “single quotes” are a real pain when copying/pasting PHP snippets in your text editor. Well done!

  22. Another idea: remove the actions that open and close the links:

    remove_action( ‘woocommerce_before_shop_loop_item’, ‘woocommerce_template_loop_product_link_open’, 10 );
    remove_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_product_link_close’, 5 );

    I would have to look further where to include these calls, to ensure that they happen *after* the corresponding add_action() calls.

    1. Awesome Damien!! It works on my dev site as well, so there is no need to “delay” the remove_action. I’m adding the solution to the blog 🙂 Keep it coming!

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 *

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