Skip to content

Instantly share code, notes, and snippets.

@MogulChris
Created July 9, 2020 21:29
Show Gist options
  • Save MogulChris/ef74a556ceb385684a63933a2c0126d9 to your computer and use it in GitHub Desktop.
Save MogulChris/ef74a556ceb385684a63933a2c0126d9 to your computer and use it in GitHub Desktop.
Custom WooCommerce product tabs from ACF repeater
<?php
//see https://gist.github.com/woogists/c15230393ba094d9da33a19a02e20a15 for the general approach to making custom tabs
add_filter( 'woocommerce_product_tabs', 'my_new_product_tabs' );
function my_new_product_tabs( $tabs ) {
$tabs = array(); //Remove default tabs (optional)
global $post;
$product_tabs = get_field('product_tabs',$post->ID); //ACF repeater
if(!empty($product_tabs)){
foreach($product_tabs as $index => $tab){
$name = sanitize_title($tab['title']); //get a 'slug' version of the title
$title = $tab['title'];
$tabs[$name] = array(
'title' => $title,
'priority' => $index,
'callback' => 'my_product_tab_content',
'content' => $tab['content'] //'content' is not a native property in a WC tab, but the whole tab will be passed to the callback function which handles output, so let's send the content along too since we already retrieved it
);
}
}
return $tabs;
}
function my_product_tab_content($tab_name,$tab) {
echo apply_filters('the_content', $tab['content']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment