Created
March 28, 2018 18:05
-
-
Save ajmorris/b9947383b553ec31559ba18f63c50c1c to your computer and use it in GitHub Desktop.
Create custom product details tabs within WooCommerce using an ACF (Advanced Custom Fields) Repeater field.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function hwid_load_custom_tab( $tab_key, $tab_info ) { | |
echo apply_filters( 'the_content', $tab_info['tabContent'] ); | |
} | |
function hwid_add_content_tabs( $tabs ) { | |
global $post; | |
$custom_tabs = get_field( 'tabs', $post->ID ); | |
foreach( $custom_tabs as $index => $tab ) { | |
$tabs['customTab-' . $index] = array( | |
'title' => $tab['tab_title'], | |
'priority' => 20 + $index, | |
'tabContent' => $tab['tab_content'], | |
'callback' => 'hwid_load_custom_tab' | |
); | |
} | |
return $tabs; | |
} | |
add_filter( 'woocommerce_product_tabs', 'hwid_add_content_tabs' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment