Support » Plugin: Custom Product Tabs for WooCommerce » Hide empty tabs EXCEPT reviews

  • Resolved neldad

    (@neldad)


    Hi Tracy, the yikes code snippet I’m using to hide empty Custom Product Tabs is below. It works great, but also hides empty Product Review tabs. Is there a modified snippet for that will hide empty Custom Product Tabs but still show empty Review tabs?

    Thanks, Tom

    // Remove Empty Tabs
    add_filter( ‘woocommerce_product_tabs’, ‘yikes_woo_remove_empty_tabs’, 20, 1 );

    function yikes_woo_remove_empty_tabs( $tabs ) {

    if ( ! empty( $tabs ) ) {
    foreach ( $tabs as $title => $tab ) {
    if ( empty( $tab[‘content’] ) && strtolower( $tab[‘title’] ) !== ‘description’ ) {
    unset( $tabs[ $title ] );
    }
    }
    }
    return $tabs;
    }

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Ebonie Butler

    (@metalandcoffee)

    Hi @neldad 👋🏾

    I made some adjustments to your code snippet that will only hide empty Custom Product Tabs and NOT empty Review tabs. Let me know how this works for you!

    
    // Remove Empty Tabs.
    add_filter( 'woocommerce_product_tabs', 'yikes_woo_remove_empty_tabs', 20, 1 );
    
    function yikes_woo_remove_empty_tabs( $tabs ) {
    	if ( ! empty( $tabs ) ) {
    		foreach ( $tabs as $title => $tab ) {
    			if ( isset( $tab['content'] ) && empty( $tab['content'] ) ) {
    				unset( $tabs[ $title ] );
    			}
    		}
    	}
    
    	return $tabs;
    }
    
    Thread Starter neldad

    (@neldad)

    Alcove Books <alcovebooks@gmail.com>
    11:49 AM (11 hours ago)
    to WordPress.org

    Hello Ebonie,

    Thanks for getting back to me, and for the new snippet. The snippet yields this error:
    Don’t Panic
    The code snippet you are trying to save produced a fatal error on line 2:

    syntax error, unexpected ‘&’

    I tried removing both &s and got new errors…

    Best, Tom

    Plugin Author Ebonie Butler

    (@metalandcoffee)

    Hi @neldad,

    I’m sorry that you are having issues with the code snippet. Are you using the Code Snippets plugin to insert the code? Does this error happen when you attempt to save the snippet?

    Would you mind providing a screenshot of what the code snippet looks like in the editor? I inserted this code snippet using the plugin and it still works as expected. See my screenshot for an example.

    Screenshot

    Thread Starter neldad

    (@neldad)

    Hi Ebonie,

    Apologies, I had the wrong snippet before…

    Anyway, I put this one into Code Snippets and got the error:

    The snippet has been deactivated due to an error on line 5:
    Cannot redeclare function yikes_woo_remove_empty_tabs.

    Error Screenshot

    Plugin Author Ebonie Butler

    (@metalandcoffee)

    Hi @neldad 🙂

    That error indicates that you have another cope snippet that is using the function name yikes_woo_remove_empty_tabs. To remedy this, you can either delete the other cope snippet that has that same function name (if you are not using it) or you can use the below code snippet I provided you with where I changed the function name to avoid the function name conflict.

    
    // Remove Empty Tabs.
    add_filter( 'woocommerce_product_tabs', 'yikes_woo_remove_empty_custom_tabs', 20, 1 );
    
    function yikes_woo_remove_empty_custom_tabs( $tabs ) {
    	if ( ! empty( $tabs ) ) {
    		foreach ( $tabs as $title => $tab ) {
    			if ( isset( $tab['content'] ) && empty( $tab['content'] ) ) {
    				unset( $tabs[ $title ] );
    			}
    		}
    	}
    
    	return $tabs;
    }
    
    Thread Starter neldad

    (@neldad)

    Of course! I forgot to disable the first snippet. Now it works perfectly.

    Thanks Ebonie Butler!

    Plugin Author Ebonie Butler

    (@metalandcoffee)

    So glad things are working now! Let us know if you need anymore help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Hide empty tabs EXCEPT reviews’ is closed to new replies.