Home › Forums › WoodMart support forum › How to hide tabs when using Advanced Custom Fields
How to hide tabs when using Advanced Custom Fields
- This topic has 1 reply, 2 voices, and was last updated 2 years, 1 month ago by Artem Temos.
-
AuthorPosts
-
November 7, 2022 at 11:07 am #419158
thomas-4251ParticipantI spent ages trying to figure this out and hope that this post is indexable on google to help others.
How to hide tabs when using Advanced Custom Fields
I wanted to show ACF fields in the Woodmart Additional Tabs area. I tried blocks but they wouldn’t update per product.In the functions file I added the below:
add_filter( 'woocommerce_product_tabs', 'woo_custom_school_tab', 98 ); function woo_custom_school_tab( $tabs ) { $schoolvalue = get_field('school'); if (!empty($schoolvalue)){ $tabs['wd_additional_tab']['callback'] = 'woo_custom_school_tab_content'; // Custom description callback }else{ unset( $tabs['wd_additional_tab'] ); // To remove the additional information tab return $tabs; } return $tabs; } /** * Reference the slug for that ACF created. */ function woo_custom_school_tab_content() { $prod_id = get_the_ID(); echo wpautop(get_field('school')); /**dont use get_post_meta($prod_id,'school',TRUE); when using wysiwyg*/ } /** Customize product data tabs - Business Tab * * * * */ add_filter( 'woocommerce_product_tabs', 'woo_custom_business_tab', 98 ); function woo_custom_business_tab( $tabs ) { $businessvalue = get_field('business'); if (!empty($businessvalue)){ $tabs['wd_additional_tab_2']['callback'] = 'woo_custom_business_tab_content'; // Custom description callback }else{ unset( $tabs['wd_additional_tab_2'] ); // To remove the additional information tab return $tabs; } return $tabs; } /** * Reference the slug for that ACF created. */ function woo_custom_business_tab_content() { $prod_id = get_the_ID(); echo wpautop(get_field('business')); } /**Customize product data tabs - Sports Tab * * * * */ add_filter( 'woocommerce_product_tabs', 'woo_custom_sports_tab', 98 ); function woo_custom_sports_tab( $tabs ) { $sportsvalue = get_field('sports'); if (!empty($sportsvalue)){ $tabs['wd_additional_tab_3']['callback'] = 'woo_custom_sports_tab_content'; // Custom description callback }else{ unset( $tabs['wd_additional_tab_3'] ); // To remove the additional information tab return $tabs; } return $tabs; } /** * Reference the slug for that ACF created. */ function woo_custom_sports_tab_content() { $prod_id = get_the_ID(); echo wpautop(get_field('sports'));; }
The if statement checks to see if the product’s ACF have content in there. If not it unsets the tab from view.
The next problem was that ACF was to wysiwyg for SEO purposes, so you have to use echo wpautop(get_field(‘sports’));; instead of get_post_meta($prod_id,’school’,TRUE); . this leaves the wysiwyg formatting.
I haven’t tested it using HTML blocks but I’ll cross that bridge later.
Tags: hide tabs with no ACF content, hide ACF Fields
November 7, 2022 at 1:12 pm #419188
Artem TemosKeymasterHello,
Thank you for posting this instruction here. We hope it will help other customers to add this feature to their websites.
Kind Regards
-
AuthorPosts
- You must be logged in to create new topics. Login / Register