大家好。有必要在档案卡中显示每个特定产品的产品标签。在functions.php中,我编写了以下代码:
function woocom_tags_list(){
$args = array( 'hide_empty' => 0 );
$terms = get_terms('product_tag', $args );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$term_list = '<ul class="my-terms-list">';
foreach ( $terms as $term ) {
$term_list .= '<li><a href="' . get_term_link( $term ) . '" title="'. $term->name .'">' . $term->name . '</a></li>';
}
$term_list .= '</ul>';
return $term_list;
}else{
return 'Тегов продуктов нет';
}
}
add_shortcode( 'woo_tags', 'woocom_tags_list' );
add_action('woocommerce_after_shop_loop_item_title', 'dosc');
function dosc() {
echo do_shortcode("[woo_tags]");
}
但它为每个产品显示相同的标签。如何解决?谢谢你。
1 个回答