小编Pel*_*out的帖子

获取 WooCommerce 订单中每件商品的产品类别

我可以检索订单商品的几乎所有元数据,但我也想检索商品的类别。

我的代码现在有这个:

foreach ($order->get_items() as $item_key => $item_values) {

    ## Using WC_Order_Item methods ##

    // Item ID is directly accessible from the $item_key in the foreach loop or
    $item_id = $item_values->get_id();

    ## Using WC_Order_Item_Product methods ##

    $item_name = $item_values->get_name(); // Name of the product
    $item_type = $item_values->get_type(); // Type of the order item ("line_item")

    $product_id = $item_values->get_product_id(); // the Product id
    $product = $item_values->get_product(); // the WC_Product object

    ## Access Order Items data properties (in an array of values) ## …
Run Code Online (Sandbox Code Playgroud)

php wordpress orders woocommerce taxonomy-terms

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

标签 统计

orders ×1

php ×1

taxonomy-terms ×1

woocommerce ×1

wordpress ×1