Uly*_*ses 1 php wordpress custom-taxonomy woocommerce taxonomy-terms
我需要产品的品牌名称,我有这个代码
$product = wc_get_product();
$type = $product->get_type();
$name = (string)$product->get_name();
$id = (int)$product->get_id();
$sku = (int)$product->get_sku();
$precio = (int)$product->get_price();
$brand_name = $product->get_brand(); ---> ???
Run Code Online (Sandbox Code Playgroud)
我得到了这个属性,但我不知道如何抓住品牌名称,还有其他方法吗?
谢谢!
Is better to use wc_get_post_terms() from a product ID (that allows to get term names instead of WP_Term Objects) and depending on what plugin you are using, the taxonomy will be different:
product_brand for Woocommerce Brands pluginyith_product_brand for YITH WooCommerce Brands pluginpa_brand for a custom product attributeSo for example with Woocommerce Brands plugin you will use:
$product_id = get_the_id();
$product = wc_get_product( $product_id );
$taxonomy = `product_brand`;
$brand_names = wp_get_post_terms( $product_id, $taxonomy, array( 'fields' => 'names' ) );
// Get the brand name
$brand_name = reset( $brand_names );
Run Code Online (Sandbox Code Playgroud)
Related:
| 归档时间: |
|
| 查看次数: |
5896 次 |
| 最近记录: |