小编Uly*_*ses的帖子

使用 WP_Query 仅显示库存产品中的 WooCommerce

我有这个代码,它显示了最好的销售,但它也显示了没有库存的产品,我如何修改代码。这样它只显示有库存的产品吗?。谢谢 !

$best_sellers_args = array(

    'post_type' => 'product', 

    'meta_key' => 'total_sales',        

    'posts_per_page' => 6,

    'orderby' =>'meta_value_num',

    'order' => 'DESC'

);

$products = new WP_Query( $best_sellers_args );
Run Code Online (Sandbox Code Playgroud)

php wordpress product stock woocommerce

2
推荐指数
1
解决办法
4105
查看次数

如何在 WooCommerce 中获取产品的品牌名称

我需要产品的品牌名称,我有这个代码

$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)

我得到了这个属性,但我不知道如何抓住品牌名称,还有其他方法吗?

在此处输入图片说明

谢谢!

php wordpress custom-taxonomy woocommerce taxonomy-terms

1
推荐指数
1
解决办法
5896
查看次数