Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hslaszlo/2349cd7d02cf9a7d5beb to your computer and use it in GitHub Desktop.
Save hslaszlo/2349cd7d02cf9a7d5beb to your computer and use it in GitHub Desktop.
Add multiple product tabs to WooCommerce 2.x
/**
* 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>Product Ingredients</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>Product Benefits</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