Sometimes WooCommerce store owners don’t want end users making it to their product detail pages. WooCommerce is a great framework and some need custom setups to accomplish their goal. For example using WooCommerce and it’s products structure to list out products that are not for sale online.
With the below snippet of code you can remove the link to the product detail page on your categories/archive WooCommerce pages.
First of all make sure you’re in your child theme and navigate to the functions.php file. Add this to the end of the file:
// Remove links to the product details pages from the product listing page of a WooCommerce store 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 );
If you want to only target a specific product category you can use this snippet in your functions.php file:
// Remove links to the product details pages from the product listing page of a WooCommerce store (only a specific category) if ( is_product() && is_product_category( array('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 ); }
If this code doesn’t work with your theme, the hooks and/or priorities may be different. Look at wp_content/themes/your-theme-name/woocommerce/content-product.php to see how your theme has done this.