我创建插件并希望从woocomerce获得品牌名称。 在第一次发布产品1号插件它的工作和获得产品品牌,但我希望当我创建产品发布2号和3号从品牌名称从产品1号得到PHP Woocomerce获得产品品牌名称
最新错了?
if (class_exists('WooCommerce')) {
$kode = $product->get_sku();
$terms = wp_get_post_terms($product_id, 'brand', array('orderby'=>'name'));
$brands = get_terms('brand', array(
'orderby' => 'name'
//,'product__in' => $product->id
// orderby arguments ('name', 'slug','term_group', 'term_id', 'id', 'description')
));
foreach ($brands as $key => $brand) :
$brand_name = $brand->name;
endforeach;
$merk = $brand_name;
//this i want to print the brand name
echo "<strong>STOCK ".$merk." ".$kode."</strong><br/>";
} else {
echo "please active your WooCommerce plugin.";
}
请帮忙,谢谢。如果你想Concat的品牌名称
$terms = wp_get_post_terms($product_id, 'brand', array('orderby'=>'name'));
//you could use: var_dump($terms); to see what it is.
,你可以这样做:
你能发布更多的代码,所以我们可以看到你在做什么。 'brand_name'将被设置为'品牌'中的最后一个值。 – GeorgeQ
我一直在编辑代码,请检查一下 –