Skip to content

Instantly share code, notes, and snippets.

@lukecav
Created October 27, 2016 02:20
Show Gist options
  • Save lukecav/48f367e68ec5db914f604f53a789a59e to your computer and use it in GitHub Desktop.
Save lukecav/48f367e68ec5db914f604f53a789a59e to your computer and use it in GitHub Desktop.
Remove Links to WooCommerce Single Product Page
// Remove Links to WooCommerce Single Product Page
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 );
@brandshore
Copy link

Adding the above code has removed the links from products.
However, I want to target only a specific category and tried the following and didn’t work, (I’ve probably got it coded wrong) any thoughts about this?

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

@benjino
Copy link

benjino commented Oct 5, 2017

Try this:

function remove_direct_link_to_product_page() { 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 ); } }

@itsourcero
Copy link

Hi!

this code works for most themes including storefront, but i just cannot make it work for oceanwp theme.
Can anyone help me with that, I tried all solutions from all threads over the net , no one works. Please help!

@lukecav
Copy link
Author

lukecav commented May 1, 2020

In that case I would check for similar issue in the WP org repo for the OceanWP theme or create a new one.
https://wordpress.org/support/theme/oceanwp/

@itsourcero
Copy link

Thank you!

i did that, but i don't think someone will ever respond :(
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment