循环显示自定义字段-Woocommerce类别

时间:2019-10-25 01:25:09

标签: wordpress woocommerce taxonomy-terms

我的网站中嵌套了类别。 我在Woocommerce类别中创建了一个自定义字段,并尝试将其添加到类别循环中。它仅显示当前类别页面的术语值

add_action( 'woocommerce_after_subcategory_title', 'custom_add_cat_Min_price', 12);

function custom_add_cat_Min_price ($category) {
 $prix_min_catt = get_term_meta(get_queried_object_id(), 'prix_min_cat', true);
 $terms = get_the_terms( $post->ID, 'prix_min_cat' );
 foreach ($terms as $term){
 echo '<div class="prixminofcatg">'.$prix_min_catt.'</div>';
 }
}

2 个答案:

答案 0 :(得分:0)

我认为问题在于您的职能范围。您已将$ category传递给函数,但尚未使用它。这会为您提供类别的ID:

function custom_add_cat_Min_price ($category) {
    $category_id = $category->term_id;

从那里,您应该能够提取自定义字段。

答案 1 :(得分:0)

感谢没有Foreach的帮助

add_action( 'woocommerce_after_subcategory_title', 'custom_addd_cat_Min_price', 29);

function custom_addd_cat_Min_price ($category) {
    $category_id = $category->term_id;
 $prix_min_cag = get_term_meta($category_id, 'prix_min_cat', true);
 $terms = get_term( $category_id, 'prix_min_cat' );
 echo '<div class="prixminofcatg">'.$prix_min_cag.'</div>';
}