Skip to content

Snippet: Remove Link to Product from WooCommerce Entries

You may want to consider instead creating a custom card for your products that simply doesn't include a thumbnail.

If for some odd reason you need to remove the links to your WooCommerce products from the entries you can do so using the following snippet.

/**
 * Removes the WooCommerce product entry links.
 *
 * @link https://total.wpexplorer.com/docs/snippets/remove-woo-entry-links/
 */
add_action( 'init', function() {

	// Woo core hooks
	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 );

	// Theme hooks
	remove_action( 'wpex_woocommerce_loop_thumbnail_before', 'woocommerce_template_loop_product_link_open', 0 );
	remove_action( 'wpex_woocommerce_loop_thumbnail_after', 'woocommerce_template_loop_product_link_close', 11 );

} );

/**
 * Modifies the WooCommerce product entry title to remove the link around it.
 *
 * @link https://total.wpexplorer.com/docs/snippets/remove-woo-entry-links/
 */
if ( ! function_exists( 'woocommerce_template_loop_product_title' ) ) {
	function woocommerce_template_loop_product_title() {
		echo '<h2 class="woocommerce-loop-product__title">' . get_the_title() . '</h2>';
	}
}
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top