Last active
May 27, 2016 16:06
-
-
Save bhwebworks/8a0a3e025fe8df1ba37e to your computer and use it in GitHub Desktop.
Add multiple product tabs to WooCommerce 2.x
This file contains hidden or 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
/** | |
* Add "Ingredients" and "Benefits" tabs to WooCommerce products | |
* | |
* @link http://blackhillswebworks.com/?p=5453 | |
* @link http://www.sean-barton.co.uk/2013/03/remove-woocommerce-20-reviews-tab | |
* @link http://www.php.net/manual/en/function.htmlspecialchars-decode.php | |
*/ | |
add_filter( 'woocommerce_product_tabs', 'bhww_woo_extra_tabs' ); | |
function bhww_woo_extra_tabs( $tabs ) { | |
global $post; | |
$product_ingredients = get_post_meta( $post->ID, '_bhww_ingredients_wysiwyg', true ); | |
$product_benefits = get_post_meta( $post->ID, '_bhww_benefits_wysiwyg', true ); | |
if ( ! empty( $product_ingredients ) ) { | |
$tabs['ingredients_tab'] = array( | |
'title' => __( 'Ingredients', 'woocommerce' ), | |
'priority' => 15, | |
'callback' => 'bhww_woo_ingredients_tab_content' | |
); | |
} | |
if ( ! empty( $product_benefits ) ) { | |
$tabs['benefits_tab'] = array( | |
'title' => __( 'Benefits', 'woocommerce' ), | |
'priority' => 16, | |
'callback' => 'bhww_woo_benefits_tab_content' | |
); | |
} | |
return $tabs; | |
} | |
function bhww_woo_ingredients_tab_content() { | |
global $post; | |
$product_ingredients = get_post_meta( $post->ID, '_bhww_ingredients_wysiwyg', true ); | |
if ( ! empty( $product_ingredients ) ) { | |
echo '<h2>' . esc_html__( 'Product Ingredients', 'woocommerce' ) . '</h2>'; | |
// Updated to apply the_content filter to WYSIWYG content | |
echo apply_filters( 'the_content', $product_ingredients ); | |
} | |
} | |
function bhww_woo_benefits_tab_content() { | |
global $post; | |
$product_benefits = get_post_meta( $post->ID, '_bhww_benefits_wysiwyg', true ); | |
if ( ! empty( $product_benefits ) ) { | |
echo '<h2>' . esc_html__( 'Product Benefits', 'woocommerce' ) . '</h2>'; | |
// Updated to apply the_content filter to WYSIWYG content | |
echo apply_filters( 'the_content', $product_benefits ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Made the h2 strings translatable, with the 'woocommerce' text domain.