3

I'd like to remove the link from the Woocommerce product listings. I don't need the user to see the product detail pages, we are going to use Quick View instead. Anywho, I have been searching and everything I've found is outdated. This is the current content-product.php file: https://github.com/woothemes/woocommerce/blob/master/templates/content-product.php and there are no anchor tags to simply remove.

I might need a hook but I'm not sure what to do. I tried a few but the link was still there. For example this didn't work when added to my functions.php:

 add_filter('woocommerce_template_loop_product_link_open','mbc_remove_link_on_thumbnail' );

 function mbc_remove_link_on_thumbnail($html){
      return strip_tags($html,'<img>');
 }

I also tried this which didn't work but I feel is close:

 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'm not sure if I'm even on the right track. Any help would be appreciated!

0

The way I've done this was to take a copy of content-product.php and paste it into the root of your theme folder.

Comment out

do_action( 'woocommerce_before_shop_loop_item_title' );

and

do_action( 'woocommerce_after_shop_loop_item' );

Quick and dirty, but it worked for me.

  • Maybe I celebrated too soon. I lost the "Add to Cart" button this way. Did this happen to you? – amandathewebdev Jan 20 '16 at 19:44
  • Ah, I'm not using the add to cart button. My site is using a plugin for Request a Quote instead. I've just deactivated the plugin and yes my add to cart button is missing too. Back to the drawing board I'm afraid. – MrFox Jan 21 '16 at 10:44
5

A better & safer way to do this is by removing the open & close link actions. This will prevent side effects such as the add to cart button disappearing.

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 );

You can add this code to your functions.php

0

I found this.

/**
 * @snippet       Disable Link to Products @ Loop
 * @how-to        Watch tutorial @ http://businessbloomer.com/?p=19055
 * @sourcecode    http://businessbloomer.com/?p=19916
 * @author        Rodolfo Melogli
 * @testedwith    WooCommerce 2.5.2
 */
// Close </a> tag just after it opens before product item

add_action( 'woocommerce_before_shop_loop_item_title','bbloomer_close_permalink', 10 );
function bbloomer_close_permalink() {
?>
</a>
<?php
}

// Open <a> tag  just before it closes after product item

add_action( 'woocommerce_after_shop_loop_item_title','bbloomer_open_atag', 11);
function bbloomer_open_atag() {
?>
<a>
<?php
}

/**
 * Explanation for the hack!
 *
 * Before the loop item, a link opens...
 * After the loop item, a link closes...
 * We're basically adding a close and open so that
 * no content gets wrapped into <a>link</a>
 * 
 * Check wc-template-functions.php lines 545-556:
 *
 * function woocommerce_template_loop_product_link_open() {
 *  echo '<a href="' . get_the_permalink() . '">';
 * }
 *
 * function woocommerce_template_loop_product_link_close() {
 *  echo '</a>';
 * }
 *
 */

Font Source: http://businessbloomer.com/woocommerce-disable-link-to-product-loop/

  • Please add an explanation as how it answers the question .. just dumping the code is not good. – bravokeyl Jul 2 '16 at 4:57
  • You right. First time in Stack. I have tried alot of 'filter' , 'remove_action_', to remove this anchor. The code i 'dumping' here, save my day. You can get more information in font source: businessbloomer.com/woocommerce-disable-link-to-product-loop – Gabriel Darezzo Jul 21 '16 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.