【发布时间】:2019-08-29 15:29:07
【问题描述】:
我几乎可以检索订单商品的所有元数据,但我也想检索商品的类别。
我的代码现在有这个:
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) ##
$item_data = $item_values->get_data();
$product_name = $item_data['name'];
$item_totaal = $item_data['subtotal'];
// Get data from The WC_product object using methods (examples)
$product_type = $product->get_type();
$product_price = $product->get_price();
}
认为这会起作用,但它不会:
$product_category = $product->get_category();
我需要什么线路?
【问题讨论】:
-
WC_Product类中没有方法get_category(),只有接近的方法是get_category_ids( string $context = 'view' ) -
是显示类别还是只显示ID?
标签: php wordpress woocommerce orders taxonomy-terms