Domanda

I'm looking like a crazy person if there is a way to display the tags of a product on the catalogue page with woocommerce ( wordpress plugin). I can not find anything about ti and I've been trying to tweak the code, but without success . . .

if anybody has some high lite, it will be wonderful,

thank you very much

È stato utile?

Soluzione

This example will show product tags on shop archive pages. The code is taken from the single product meta template ( single-product/meta.php ), so HTML will be the same as in single product pages. The function is hooked to woocommerce_after_shop_loop_item action ( the tags will be between the main content and the add_to_cart content ), if you want to place them elsewhere open the content-product.php and wc-template-hooks.php plugin files, to see all the available actions and priorities of functions attached, and attach woocommerce_product_loop_tags function to a different action.

add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_product_loop_tags', 5 );

function woocommerce_product_loop_tags() {
    global $post, $product;

    $tag_count = sizeof( get_the_terms( $post->ID, 'product_tag' ) );

    echo $product->get_tags( ', ', '<span class="tagged_as">' . _n( 'Tag:', 'Tags:', $tag_count, 'woocommerce' ) . ' ', '.</span>' );
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top