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
.
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 );
}