Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bhwebworks/8a0a3e025fe8df1ba37e to your computer and use it in GitHub Desktop.
Save bhwebworks/8a0a3e025fe8df1ba37e 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>' . 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 );
}
}
@bhwebworks
Copy link
Author

Made the h2 strings translatable, with the 'woocommerce' text domain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment