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 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Made the h2 strings translatable, with the 'woocommerce' text domain.