Home › Forums › WoodMart support forum › Need help with custom tab
Need help with custom tab
- This topic has 4 replies, 2 voices, and was last updated 6 years, 11 months ago by Artem Temos.
-
AuthorPosts
-
January 12, 2018 at 11:56 am #33153
MoeMauphieParticipantHi there,
First off thank you very much for the recent update.
I’ve added a new tab on product page to show a specific attribute there. I used the code snippet for the brand attribute which is available on the theme. I did manage to get it working but I have a small problem: When a product doesn’t have that specific attribute, although the tab is not shown, it still outputs html markup for that attribute which creates some extra gap between tabs.
Here is the code that I have added to the function.php:
/** * ------------------------------------------------------------------------------------------------ * Add product tech tab to the single product page * ------------------------------------------------------------------------------------------------ */ add_filter( 'woocommerce_product_tabs', 'woodmart_product_tech_tab' ); if( ! function_exists( 'woodmart_product_tech_tab' ) ) { function woodmart_product_tech_tab( $tabs ) { global $product; $attribute = 'pa_tech'; $techs_attribute = $product->get_attribute( $attribute ); if ( $techs_attribute ) { $tabs['tech_tab'] = array( 'title' => esc_html__( 'About Tech', 'woodmart' ), 'priority' => 50, 'callback' => 'woodmart_product_tech_tab_content' ); } return $tabs; } } if( ! function_exists( 'woodmart_product_tech_tab_content' ) ) { function woodmart_product_tech_tab_content() { global $product; $attr = "pa_tech"; if( ! $attr ) return; $attributes = $product->get_attributes(); if( ! isset( $attributes[ $attr ] ) || empty( $attributes[ $attr ] ) ) return; $techs = wc_get_product_terms( $product->get_id(), $attr, array( 'fields' => 'slugs' ) ); if( empty( $techs ) ) return; foreach ($techs as $id => $slug) { echo '<div class="woodmart-product-tech-description">'; $tech = get_term_by('slug', $slug, $attr); echo do_shortcode( $tech->description ); echo '</div>'; } } }
I suppose I’m going to need some conditions there to prevent it forming outputting html when there’s no attribute. Since I’m not a coder I came here to seek you help. I’d really appreciate if you could help me with that.
Thanks a lot,
January 12, 2018 at 12:38 pm #33159
MoeMauphieParticipantSolved. It was because I was recording tabs.
January 12, 2018 at 2:26 pm #33186
Artem TemosKeymasterGreat, we are glad that you have found the solution.
January 13, 2018 at 6:39 am #33233
MoeMauphieParticipantSolved. It was because I was recording tabs
Of course I meant “reordering” not “recording” :-)) Bloody auto-correction!
January 13, 2018 at 10:32 am #33253
Artem TemosKeymasterYes, we got it 🙂
-
AuthorPosts
- You must be logged in to create new topics. Login / Register