Skip to content

Instantly share code, notes, and snippets.

@jmarreros
Last active August 19, 2021 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmarreros/ed2b577e810830bcade91eac94c12eac to your computer and use it in GitHub Desktop.
Save jmarreros/ed2b577e810830bcade91eac94c12eac to your computer and use it in GitHub Desktop.
Muestra las etiquetas de un producto en la lista de productos WooCommerce
<?php // No copiar esta línea
add_action( 'woocommerce_after_shop_loop_item_title', 'dcms_tags_item_product', 10, 0 );
function dcms_tags_item_product() {
if ( ! is_shop() ) return;
global $product;
$product_data = $product->get_data();
$tag_ids = $product_data['tag_ids'];
if ( ! count($tag_ids) ) return;
print("<section class='item-tags'>");
foreach ($tag_ids as $tag_id){
$term_object = get_term_by('id', $tag_id, 'product_tag');
$tag_name = $term_object->name;
$tag_link = get_tag_link($tag_id);
printf("<a href='%s' title='%s'>%s</a>",$tag_link, $tag_name, $tag_name);
}
print("</section>");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment