• Resolved teshn

    (@teshn)


    Hi,

    I want to import a csv with WP All Import and create new products. Some products e.g. have something called “autor information”, which is empty sometimes, same goes for other columns. I created a tab for each column.

    Can I hide tabs automatically on products which have an empty tab content?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello @teshn,

    This is logic that you would need to workout in your themes custom tab template. If you aren’t already overriding the tab template you would do it like this:
    https://docs.woocommerce.com/document/template-structure/

    Once you have your tab template in your theme you would do something like this in the template:

    
    $product_tabs = apply_filters( 'woocommerce_product_tabs', array() );
    
    $product_tabs = array_filter( $product_tabs, 'filter_empty_tabs', ARRAY_FILTER_USE_BOTH );
    
    function filter_empty_tabs( $key, $product_tab ) {
        $tab_content = '';
        if ( isset( $product_tab['callback'] ) ) {
            ob_start();
            call_user_func( $product_tab['callback'], $key, $product_tab );
            $tab_content = ob_get_contents();
            ob_end_flush();
        }
        return (bool)($tab_content !== '');
    }
    

    This will call the tab content callback and filter out any tabs that don’t have content.

    Cheers,
    Freddie

    • This reply was modified 4 years, 5 months ago by Freddie. Reason: Adding support for key

    I’m going to be adding a tutorial for this on the yikesplugins.com knowledge base and we have a bunch of other tutorials there you could check out!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hiding empty tabs, although empty tabs are not allowed’ is closed to new replies.