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

silumantu

Member
Oct 9, 2019
169
23
18
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?
 

Hardii

Well-known member
Trusted Uploader
Jul 1, 2022
146
481
63
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: silumantu

silumantu

Member
Oct 9, 2019
169
23
18
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.
 

Latest posts

Forum statistics

Threads
69,228
Messages
908,447
Members
237,061
Latest member
itachii

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu