Last active
October 14, 2019 04:13
-
-
Save nmedia82/1a7fa42dc6e8235c7eb2591414b234ff to your computer and use it in GitHub Desktop.
Hiding Yith inquiry tab for certain categories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
** Hiding for tab for following categories | |
** Signage | |
** 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