1

I've added the following code to my child theme's function.php to exclude the category "workshops" from displaying Woocommerce Related Products. How would I add in a 2nd category (ie. events) to this code? Thanks.

add_action( 'wp', 'vn_remove_related_products' );
function vn_remove_related_products() {
  if ( is_product() && has_term( 'workshops', 'product_cat' ) ) {
        remove_action( 'woocommerce_after_single_product_summary', 
'woocommerce_output_related_products', 20 );
  }
}

1 Answer 1

1
add_action( 'wp', 'vn_remove_related_products' );
function vn_remove_related_products() {
  if ( is_product() && has_term( array('workshops', 'events'), 'product_cat' ) ) {
        remove_action( 'woocommerce_after_single_product_summary', 
'woocommerce_output_related_products', 20 );
  }
}

Function has_term() can pass first parameter as array with terms.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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