Sometimes you need to add some extra tabs on a single page.
It’s very easy to add extra tabs, before adding tabs you need to create custom
fields to add tab content from the backend.
I am using ACF(Advance custom fields) plugin to create custom fields.
I am creating two custom fields with Wysiwyg Editor option.
I am going to add two product tabs FAQ and Health Notes.
Add below code to your theme functions.php
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
add_filter( 'woocommerce_product_tabs', 'add_extra_tabs' ); function add_extra_tabs( $tabs ){ $tabs['faq'] = array( 'title' => __( 'FAQ', 'woocommerce' ), 'priority' => 31, 'callback' => 'faq_tab_content' ); $tabs['healthnotes'] = array( 'title' => __( 'Health Notes', 'woocommerce' ), 'priority' => 32, 'callback' => 'healthnnotes_tab_content' ); return $tabs; } //callback faq function faq_tab_content() { global $post; $faq = get_post_meta( $post->ID, 'faq', true ); echo apply_filters( 'the_content', $faq ); } //callback healthnotes function healthnnotes_tab_content() { global $post; $healthnotes = get_post_meta( $post->ID, 'health_notes', true ); echo apply_filters( 'the_content', $healthnotes ); } |