On our WooCommerce WordPress product page, I was able to remove the 'Additional Information; tab with the following code:
add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
function woo_remove_product_tabs( $tabs ) {
unset( $tabs['additional_information'] ); // Remove the additional information tab
return $tabs;
}
However we have an additional tab 'Sizing' we want this to show on one of our two main categories (show only on one category).
I have tried running the above along with:
add_filter( 'woocommerce_product_tabs', 'conditionaly_removing_product_tabs', 99 ); function conditionaly_removing_product_tabs( $tabs ) {
//get all categories
$terms = wp_get_post_terms( $product_id, 'synthetic-wigs' );
foreach ( $terms as $term ) {
$categories[synthetic-wigs] = $term-synthetic-wigs;
}
if ( in_array( 'synthetic-wigs', $categories ) ) {
unset( $tabs['sizing'] ); // (Sizing tab)
unset( $tabs['additional_information'] ); // (Additional information tab)
}
return $tabs;
}
This didn't work and caused a critical error. How can I remove one tab from all and another tab from just one?
Page example: https://www.lacefronts.com.au/product/lace-front-human-hair-wig-light-blonde-bob-with-bangs-wig-6-inch-bron/
New image: https://www.lacefronts.com.au/wp-content/uploads/2023/08/Lace-Fronts-Australia-wig-size-chart.png
There are multiple issues, but to start, the category array key is missing the quotation marks and the new value should reference an array.
To fix the critical error, it should help to update this:
$categories[synthetic-wigs] = $term-synthetic-wigs;
to this:
$categories['synthetic-wigs'] = $term['synthetic-wigs'];