Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tamarazuk/c8d68c988b78849be3e6 to your computer and use it in GitHub Desktop.
Save tamarazuk/c8d68c988b78849be3e6 to your computer and use it in GitHub Desktop.
WooCommerce Tab Manager - Conditionally hide tab
<?php
function wc_tab_manager_product_tabs_hide_books_tab( $tabs ) {
global $product;
// + check if we are on the product page before removing the tab so that the
// tab still displays in the admin
// + change some_condition() to a function/variable which returns true if the
// product should be displayed
// + "unique-tab-name" is uniquely generated by Tab Manager and can be found by
// inspecting the source on a product page and finding the HTML which outputs
// the tab. It will look like:
// <a href="#tab-unique-tab-name">Your tab name here</a>
if ( $product && ! some_condition( $product ) ) {
// remove tab with name "unique-tab-name"
unset( $tabs['unique-tab-name'] );
}
return $tabs;
}
add_filter( 'wc_tab_manager_product_tabs', 'wc_tab_manager_product_tabs_hide_books_tab' );
function some_condition( $product ) {
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment