I made a function for Woo store to display custom taxonomies. And somehow my span conatiners for each are destroyed. Here's the code:
add_action( 'woocommerce_product_meta_start', 'add_my_meta', 1 );
function add_my_meta() {
$series = the_terms($post->ID, 'series');
if ($series) {
$meta_output = '<span style="display:block;">Series: ';
$meta_array = array();
foreach ($series as $serie) {
$meta_array[] = '<a href="' . get_term_link( $serie->slug, 'series') .'">' . $serie->name . '</a>';
}
$meta_output .= join( ', ', $meta_array ) . '</span>';
}
return $meta_output;
}
So expected output is <span style="display:block;">Series: <a href="https://example.com/series/myseries/" rel="tag">My Series</a></span>
Current output is <a href="https://example.com/series/myseries/" rel="tag">My Series</a>
Spans and text removed. Never faced that problem before, what's the problem and how to solve?
Found some mistakes — needed to use get_the_terms (was the_terms) and $serie->term_id (was $serie->slug)
add_action( 'woocommerce_product_meta_start', 'add_my_meta', 1 );
function add_my_meta() {
$series = get_the_terms($post->ID, 'series');
if ( is_array($series) ) {
$meta_array = array();
foreach ($series as $serie) {
$meta_array[] = '<a href="' . get_term_link( $serie->term_id, 'series') .'">' . $serie->name . '</a>';
}
echo '<span class="tagged_as">Series: ' . implode( ', ', $meta_array ) . '</span>';
}
}