display tags on catalogue pages woo commerce - wordpress

烂漫一生 提交于 2020-01-15 11:13:30

问题


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


回答1:


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>' );
}


来源:https://stackoverflow.com/questions/22753220/display-tags-on-catalogue-pages-woo-commerce-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!