Php 在产品标题中显示特定父产品的子产品类别

Php 在产品标题中显示特定父产品的子产品类别,php,wordpress,woocommerce,product,taxonomy-terms,Php,Wordpress,Woocommerce,Product,Taxonomy Terms,我在WooCommerce的类别中设置了品牌,如图所示 我想将这个类别的术语输出到产品的标题中,并带有一个链接,链接到该品牌的所有光盘 我创建了这个功能,但它向所有产品显示所有品牌,而不仅仅是指定的品牌 add_action( 'woocommerce_shop_loop_item_title', 'get_brand', 10 ); function get_brand() { $terms = get_terms( array( 'taxonomy'

我在WooCommerce的类别中设置了品牌,如图所示

我想将这个类别的术语输出到产品的标题中,并带有一个链接,链接到该品牌的所有光盘

我创建了这个功能,但它向所有产品显示所有品牌,而不仅仅是指定的品牌

add_action( 'woocommerce_shop_loop_item_title', 'get_brand', 10 );

function get_brand() {

  $terms = get_terms(
      array(
          'taxonomy'   => 'product_cat',
          'hide_empty' => false,
          'child_of'   => 32
      )
  );

  // Check if any term exists
  if ( ! empty( $terms ) && is_array( $terms ) ) {
      // Run a loop and print them all
      foreach ( $terms as $term ) { ?>
          <a href="<?php echo esc_url( get_term_link( $term ) ) ?>">
              <?php echo $term->name; ?>
          </a><?php
      }
  }

}
add_action('woocommerce_shop_loop_item_title','get_brand',10);
函数get_brand(){
$terms=获取条款(
排列(
“分类法”=>“产品分类”,
“hide_empty”=>false,
'child_of'=>32
)
);
//检查是否存在任何术语
if(!empty($terms)&&is_数组($terms)){
//运行一个循环并将它们全部打印出来
foreach($terms作为$term){?>

要为产品设置产品类别术语(定义一些参数),您需要使用“品牌”的正确父术语参数,如下所示:

add_action('woocommerce_shop_loop_item_title','display_loop_brand',10);
功能显示\u回路\u品牌(){
$taxonomy='product_cat';
//获取产品的“品牌”子术语集
$brand_terms=(数组)wp_get_post_terms(get_the_id(),$taxonomy,数组(
“hide_empty”=>false,

'parent'=>32//您是否尝试使用此代码获取条款?
$terms=get_the_terms($post->ID,'product_cat');