• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

How to hide woocommerce additional information tab if the content is empty?

Iron-Man

Active member
Babiato Lover
Oct 9, 2019
304
87
28
29
India
I have 5 tabs in my woocommerce site including additional information tabs plus 2 custom tabs created by my theme. I am using bellow snippet to reorder them in the single product page.

add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 );
function woo_reorder_tabs( $tabs ) {

$tabs['description']['priority'] = 5; // Description first
$tabs['additional_information']['priority'] = 10; // Additional information second
$tabs['wd_additional_tab']['priority'] = 15; // custom tab by woodmart third
$tabs['wd_additional_tab_2']['priority'] = 20; // custom tab by woodmart fourth
$tabs['reviews']['priority'] = 25; // Reviews last

return $tabs;
}


The problem is when the additional information tab is empty, it shows a blank tab in the single product frontend. It is even happening without using the above snippet. I tried various snippet to solve this like this , this etc. but they are not working properly. Some are even completely hiding the additional information tab.

So is there any snippet to hide additional information tab when its content is empty?
 
Try the following

Code:
add_filter( 'woocommerce_product_tabs', 'babiato_remove_product_tabs', 98 );


function babiato_remove_product_tabs( $tabs ) {

    global $product;
     $id = $product->get_id();

    $my_custom_data = get_post_meta($id, 'babiato', true );

    if(empty($my_custom_data)) {
        unset( $tabs['additional_information'] );      // Remove the additional information tab
    }

    return $tabs;
}
 
Last edited:
  • Like
Reactions: Iron-Man
Try the following

Code:
add_filter( 'woocommerce_product_tabs', 'babiato_remove_product_tabs', 98 );


function babiato_remove_product_tabs( $tabs ) {

    global $product;
     $id = $product->get_id();

    $my_custom_data = get_post_meta($id, 'babiato', true );

    if(empty($my_custom_data)) {
        unset( $tabs['additional_information'] );      // Remove the additional information tab
    }

    return $tabs;
}
Thanks for replay. I tried the snippet. It successfully hide additional information tab when there is no content 😃. But it is also completely hiding the additional information tab even if there is some content😢. I guess there may need little change in this snippet.
 

Forum statistics

Threads
79,588
Messages
1,145,760
Members
250,440
Latest member
Sela
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock