在搞乱了代码之后,我找到了一个解决方案,可以在产品归档页面的销售标签下面直接添加一个分类标签。
//Tonen van Nieuw-label op archive page
function show_new_label(){
//Check all the categories of taxonomy product_cat
$argsTax = array(\'orderby\' => \'name\', \'order\' => \'ASC\', \'fields\' => \'all\');
$terms = wp_get_post_terms(get_the_id(), \'product_cat\', $argsTax);
if(count($terms) > 0){
foreach($terms as $term){
$output .= $term->name; //name, slug, term_id, term_group, term_taxonomy_id, taxonomy, description, parent, count
}
};
//Store all taxonomies in a variable
$outputVar = $output;
//Check if the right taxonomy is stored in the variable
if(strpos($outputVar, \'New\') !== false){
echo \'<p class="new-lable">New</p>\';
} else{
}
}
//Attach the function to the \'woocommerce_before_shop_loop_item\'-loop
add_action( \'woocommerce_before_shop_loop_item\', \'show_new_label\', 10 );
也许不是最干净的代码,但它工作得很完美