Created
July 30, 2016 14:49
-
-
Save corilam/ef1410a43811029576e8de3aa626c1c8 to your computer and use it in GitHub Desktop.
Woocommerce Custom Tabs with 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
// This version works with an ACF with the name 'new' | |
// 1.Displays the tab on every product page | |
add_filter( 'woocommerce_product_tabs', 'woo_new_tab' ); | |
function woo_new_tab( $tabs ) { | |
// Adds the new tab | |
$tabs['new'] = array( | |
'title' => __( 'New', 'woocommerce' ), | |
'priority' => 20, | |
'callback' => 'woo_new_tab_content' | |
); | |
return $tabs; | |
} | |
function woo_new_tab_content() { | |
// The new tab content | |
echo $variable = get_field('new'); | |
} | |
// 2. This variation allows you to only add the tab to specific product categories | |
add_filter( 'woocommerce_product_tabs', 'woo_new_tab' ); | |
function woo_new_tab( $tabs ) { | |
if ( is_singular('product') && (has_term( 'your-cat', 'product_cat')) ) { | |
// Adds the new tab | |
$tabs['new'] = array( | |
'title' => __( 'New', 'woocommerce' ), | |
'priority' => 20, | |
'callback' => 'woo_new_tab_content' | |
); | |
} | |
return $tabs; | |
} | |
function woo_new_tab_content() { | |
// The new tab content | |
echo $variable = get_field('new'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment