I have created a custom taxonomy (shipment-status) for WooCommerce products having two terms i.e [Shipped from abroad & Available now]
Only one term is selected per product. I will like to show the selected term above the WooCommerce product title on the single product page and on the archive card as seen in the images below. I would like to style the two terms differently, so will like to have a class attached to them.
Am currently using the snippet below to display it but how do i change the class based on the term name or id?
add_action( 'woocommerce_before_shop_loop_item_title', 'add_artist_term');
function add_artist_term() {
$terms = wp_get_post_terms(get_the_ID(), 'shipment-status');
if (!is_wp_error($terms) && !empty($terms)) { ?>
<div class="shipment-status"><a href="<?php echo esc_url(get_term_link($terms[0])); ?>"><?php echo esc_html($terms[0]->name); ?></a></div>
<?php }
}
Thanks in advance for helping.
source https://stackoverflow.com/questions/69758997/show-custom-taxonomy-before-woocommerce-product-title
Comments
Post a Comment