我可以检索订单商品的几乎所有元数据,但我也想检索商品的类别。
我的代码现在有这个:
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)