Created
December 27, 2013 05:40
-
-
Save justinstern/8142999 to your computer and use it in GitHub Desktop.
Sample code for the WooCommerce Tab Manager plugin to conditionally display a tab based on the product category. To use this code, first go to WooCommerce > Tab Manager > Add Global Tab and create a new global tab, which for this example we'll name "Sample Tab". "Sample Tab" will now show up for every product that uses the global tab layout. Let…
This file contains hidden or 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
| <?php | |
| add_filter( 'wc_tab_manager_product_tabs', 'wc_tab_manager_product_tabs' ); | |
| function wc_tab_manager_product_tabs( $tabs ) { | |
| global $product; | |
| foreach ( $tabs as $tab_name => $tab ) { | |
| if ( 'my-tab' == $tab_name ) { | |
| $categories = wp_get_post_terms( $product->id, 'product_cat', array( 'fields' => 'names' ) ); | |
| if ( ! in_array( 'My Category', $categories ) ) { | |
| unset( $tabs[ $tab_name ] ); | |
| } | |
| } | |
| } | |
| return $tabs; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Justin, and thanks for sharing this snippet! I tried this code but had no luck. What I'm trying to achieve is to set the Global tabs to 1 category.
I've added this to my theme's functions.php
Here's my code: