Skip to content

Instantly share code, notes, and snippets.

@rushijagani
Created September 24, 2018 11:39
Show Gist options
  • Save rushijagani/dbf1b62de0ddef534b58974358ea9510 to your computer and use it in GitHub Desktop.
Save rushijagani/dbf1b62de0ddef534b58974358ea9510 to your computer and use it in GitHub Desktop.
Display a specific product tag on shop/category archive page.
<?php
// Display a specific product tag on shop/category archive page.
add_action( 'woocommerce_before_shop_loop_item', 'woocommerce_poruct_tags_before_shop_loop', 7 );
function woocommerce_poruct_tags_before_shop_loop(){
// get product_tags of the current product
$current_tags = get_the_terms( get_the_ID(), 'product_tag' );
//only start if we have some tags
if ( $current_tags && ! is_wp_error( $current_tags ) ) {
//create a list to hold our tags
echo '<div class="product_tags">';
//for each tag we create a list item
foreach ($current_tags as $tag) {
$tag_title = $tag->name; // tag name
$tag_link = get_term_link( $tag );// tag archive link
echo '<a href="'.$tag_link.'">'.$tag_title.'</a>';
}
echo '</div>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment