Skip to content

Instantly share code, notes, and snippets.

@nmedia82
Last active October 14, 2019 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmedia82/1a7fa42dc6e8235c7eb2591414b234ff to your computer and use it in GitHub Desktop.
Save nmedia82/1a7fa42dc6e8235c7eb2591414b234ff to your computer and use it in GitHub Desktop.
Hiding Yith inquiry tab for certain categories
/**
** Hiding for tab for following categories
** Signage
** print
** Signage + print
** Crystal awards
**/
// Paste collowing code inside your theme's functions.php file
if ( function_exists( 'YITH_WCTM' ) ) {
add_filter( 'ywctm_get_vendor_option', 'nmedia_inquiry_tab', 10, 3 );
function nmedia_inquiry_tab( $value, $post_id, $option ) {
if ( $option == 'ywctm_inquiry_form_type' && ! YITH_WCTM()->check_add_to_cart_single( true, $post_id ) && !nmedia_if_category_found($post_id) ) {
$value = 'none';
}
return $value;
}
}
// Check for your categories
// Return 'boolean'
function nmedia_if_category_found($post_id) {
// Getting slugs of all categories
$terms = wp_get_post_terms( $post_id, 'product_cat' );
foreach ( $terms as $term ) $wc_categories[] = $term->slug;
$show_cat = array('signage', 'printing','signage-print','crystal-awards');
$found_cat = false;
// Now check against your categories with 'slug'
if ( in_array( $show_cat, $wc_categories ) ) {
found_cat = true;
}
return $found_cat;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment