fatBuzz of Fatbuzz Development Team
12/18/2017 - 10:45 AM

WooCommerce add custom product tab

Add custom-product-tabs.php to functions.php.

Add a repeater field for products with a field name of 'tabs', add 2 sub-fields, 'tab_title' ad 'tab_content'.

<?php
// WooCommerce add a custom tab
function load_custom_tab( $tab_key, $tab_info ) {

echo apply_filters( 'the_content', $tab_info['tabContent'] );

}

function add_content_tabs( $tabs ) {

global $post;

$custom_tabs = get_field( 'tabs', $post->ID );

if ( $custom_tabs ) :

   foreach( $custom_tabs as $index => $tab ) {

   $tabs[$tab['tab_tite']] = array(

   'title' => $tab['tab_title'],

   'priority' => 50 + $index,

   'tabContent' => $tab['tab_content'],

   'callback' => 'load_custom_tab'

);

}

endif;

return $tabs;

}

add_filter( 'woocommerce_product_tabs', 'add_content_tabs' );