繁体   English   中英

Woocommerce-在商品名称中添加姓氏名称

[英]Woocommerce - add last category name to product name

如何显示产品的姓氏名称? 我想将产品名称与最后一个类别的名称结合使用https://screenshotscdn.firefoxusercontent.com/images/0b7c1ee5-6b2a-4e26-bf9e-1c44084abc5c.png

尝试这样的事情:

// get all product cats for the current post
$categories = get_the_terms( get_the_ID(), 'product_cat' ); 

// wrapper to hide any errors from top level categories or products without category
if ( $categories && ! is_wp_error( $category ) ) : 

// loop through each cat
foreach($categories as $category) :
  // get the children (if any) of the current cat
  $children = get_categories( 
      array ('taxonomy' => 'product_cat', 'parent' => $category->term_id )
  );

  if ( count($children) == 0 ) {
      // if no children, then echo the category name.
      echo $category->name;
  }
endforeach;

endif;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM