Home Forums WoodMart support forum Conditionally show product tab

Conditionally show product tab

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #131009

    twgerber
    Participant

    In the woodmart theme I have set up an additional tab called “Delivery Forms”.

    This tab is only applicable to certain product categories.

    Can I set up a condition so it doesn’t show for certain categories?

    Thank you

    For example it should show for Dog products: https://vitalplanet.com/supplements/flora-dog-20-billion-probiotic-powder-vs/
    But not for human products like: https://vitalplanet.com/supplements/vital-flora-womens-daily-55-probiotic/

    #131030

    Hello,

    Product page and tabs are Woocommerce functionality, and Woocommerce does not provide the option by default.

    Perhaps you can try searching for a plugin.

    Best Regards

    #131161

    twgerber
    Participant

    I will look. Since I set it up on the theme I thought the tab was under theme control

    Thx

    #131176

    Hello,

    The theme provides the option of an additional tab on the product page. You can create HTML block for dogs and insert it in the additional tab for all dogs products. https://xtemos.com/docs/woodmart/product-page-options/

    Best Regards

    #131512

    twgerber
    Participant

    Can I not add some custom CSS to hide the extra tab for a single products like:

    /* removes the image on product id = 8885 */
    .postid-8885 .woodmart_additional_tab_tab {
    display:none;
    }

    I must not have my CSS quite right because it’s not working 😉

    #131516

    newsprince
    Participant

    @twgerber

    1st. Install this plug-in

    https://wordpress.org/plugins/code-snippets/

    2nd. Create a new snippet and paste the following code:

    add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
    
    function woo_remove_product_tabs( $tabs ) {
    	
      	if ( has_term( array('human-health'), 'product_cat') ){
    	  
    	  unset( $tabs['additional_information'] );  	// Remove the additional information tab
    	  //unset( $tabs['woodmart_custom_tab'] );  	// Remove the custom information tab
    	  
    	}
        
    
        return $tabs;
    }
    

    Now on category human health the tab will not be shown.

    #131518

    twgerber
    Participant

    Thanks I will try this.

    #131519

    twgerber
    Participant

    Doesn’t seem to do anything 🙁

    #131520

    newsprince
    Participant

    @twgerber

    Did you activate the snippet (Save and activate – Run everywhere)?

    Did you clear your cache?

    #131522

    twgerber
    Participant

    Yes, yes and yes 😉

    I will go thru it again.

    #131523

    twgerber
    Participant

    No still not working. I even uncommented the two unset lines.

    Shows as active and I cleared WP Rocket cache.

    #131524

    newsprince
    Participant

    Sorry it was Woodmart’s additional tab. Try this code again

    add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
    
    function woo_remove_product_tabs( $tabs ) {
    	
      	if ( has_term( array('human-health'), 'product_cat') ){
    	  
    	  unset( $tabs['woodmart_additional_tab'] );  	// Remove the additional information tab
    	  //unset( $tabs['woodmart_custom_tab'] );  	// Remove the custom information tab
    	  
    	}
        
    
        return $tabs;
    }

    Clear cache after

    #131525

    twgerber
    Participant

    I exported the snippet to add.

    #131526

    twgerber
    Participant

    That did it!!!

    Thanks!

Viewing 14 posts - 1 through 14 (of 14 total)