Created
February 25, 2016 09:39
-
-
Save ashwebstudio/65dd84ee5246c5f5a467 to your computer and use it in GitHub Desktop.
WooCommerce tabs using Advanced Custom Fields
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
// First create a field group assigned to the Product custom post type | |
// Make a repeater field with sub-fields "Title" (text) and "Content" (WYSIWYG) | |
add_filter( 'woocommerce_product_tabs', 'custom_tabs' ); | |
function custom_tabs( $tabs ) { | |
global $post; | |
$priority = 100; | |
while ( has_sub_field( 'tabs', $post->ID ) ) { | |
$title = get_sub_field( 'title' ); | |
$content = get_sub_field( 'content' ); | |
$id = sanitize_title( $title ); | |
$id = str_replace( '-', '_', $id ); | |
$tabs[ $id ] = array( | |
'title' => $title, | |
'priority' => $priority++, | |
'callback' => 'custom_tab_content' | |
); | |
} | |
return $tabs; | |
} | |
function custom_tab_content( $id ) { | |
global $post; | |
while ( has_sub_field( 'tabs', $post->ID ) ) { | |
$title = get_sub_field( 'title' ); | |
$this_id = sanitize_title( $title ); | |
$this_ = str_replace( '-', '_', $this_ ); | |
if ( $id == $this_id ) { | |
the_sub_field( 'content' ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just if anyone had a problem with this script. On line 31:
$this_ = str_replace( '-', '', $this ); is missing the id at the end:
$this_id = str_replace( '-', '_', $this_id );