Outputting an array of term meta values in a custom WooCommerce tab?

Forgive me – my WordPress/PHP skills are hilariously rudimentary, so I may not use the correct terminology.

I have added a custom tab to the WooCommerce single product page and need it to display a number (sometimes single, sometimes multiple) of term meta values related to a custom taxonomy, ‘book-author’. These values are created in a WYSIWYG editor and contain HTML formatting. Each ‘book-author’ has an author bio (the term meta ‘wpcf-author-biography’), and each WooCommerce product has one or more ‘book-authors’ attributed to it.

This is the code I’m currently using:

// Add author bio tab

add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {

// Adds the new tab

$tabs['author_tab'] = array(
    'title'     => __( 'About the author', 'woocommerce' ),
    'priority'  => 50,
    'callback'  => 'woo_new_product_tab_content'

return $tabs;


// Add the content

function woo_new_product_tab_content() {

$terms = get_the_terms(get_the_ID(), 'book-author' );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
foreach ( $terms as $term ) {
    $all_term_meta = get_term_meta($term->term_id, 'wpcf-author-biography', false);

It took me forever to get to this point, and while the relevant data is finally being output, the frontend result leaves a lot to be desired. This is how it ends up:

<div class="woocommerce-Tabs-panel woocommerce-Tabs-panel--author_tab panel 
entry-content wc-tab" id="tab-author_tab" role="tabpanel" aria-
labelledby="tab-title-author_tab" style="display: block;">
[0] =&gt; XX staff writer&nbsp;<strong>John Doe</strong>&nbsp;has covered 
everything from men's&nbsp;style and grooming to food, drinks and travel. John 
has also interviewed&nbsp;some of the biggest names in film, television and 
[0] =&gt; <div class="woocommerce-tabs wc-tabs-wrapper">
<div id="tab-test_tab" class="woocommerce-Tabs-panel woocommerce-Tabs-panel--
test_tab panel entry-content wc-tab" style="display: none;">

<strong>Jane Doe&nbsp;</strong>is an author and university 
lecturer&nbsp;in underwater basket-weaving. She has recently completed a PhD.


While the tab itself is created without any issues, as you can see, I’m getting some rogue Arrays being displayed as well as some other guff, and the second term meta value is for some reason being stuck in its own hidden tab wrapper, when it should appear in the same tab.

Obviously I’m not going about this the right way otherwise I wouldn’t be here, so any help or push in the right direction would be greatly appreciated.

Additionally, if there’s any way to implement a condition so that if there is no ‘book-author’ attributed to the product, no ‘About the author’ tab appears, that would be most helpful…

Thanks in advance!

Read more here: Outputting an array of term meta values in a custom WooCommerce tab?

Leave a Reply

Your email address will not be published. Required fields are marked *