2条回答 默认 最新
- dtqpw68806 2019-03-15 04:52关注
To get all order item meta data, you will use
WC_Order_Item
get_formatted_meta_data()
method with specific arguments, this way:// Accessible non protected Order item meta data $item_meta_data = $item->get_formatted_meta_data( '', true ); // Formatted raw Output echo '<pre>'; print_r($item_meta_data); echo '</pre>';
To access some order item properties, you can use any
WC_Order_Item_Product
method like:$item->get_product(); // Get the WC_Product object $item->get_product_id(); // Get the Product ID $item->get_variation_id(); // Get the Variation ID $item->get_name(); // Get the Product name $item->get_quantity(); // Get the item quantity // and so on …
Then if you need to access a specific "custom" order item data value, you will use
WC_Data
get_meta()
method:$custom_value = $item->get_meta("_custom_key");
See: Get Order items and WC_Order_Item_Product in Woocommerce 3
Update (displaying your required custom order item meta data)
The data you need can be accessed and displayed this way:
if( $lessons = $item->get_meta('lessons') ) { echo '<p>Lessons: '.$lessons.'</p>'; } if( $tour_guide = $item->get_meta('tour guide') ) { echo '<p>Tour Guide: '.$tour_guide.'</p>'; }
I hope that this works now.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 怎么实现数组的循环累加,simulink
- ¥15 51单片机最小开发板系统,想让寻迹小车在全检测到黑线(寻迹模块代码在第一块板子上)时蜂鸣器响(在第二块板子上)
- ¥15 pbootcms多选调用成列表
- ¥15 51单片机oled显示时钟
- ¥15 小规模TSP问题的动态规划求解
- ¥25 kubelet.service: Failed with result 'exit-code'.
- ¥15 bitvise黑框内一键部署v2ray提示账户没有root怎么解决
- ¥15 车型识别以及相似度匹配中细节特征提取以及图像模糊问题
- ¥15 怎么用鸿蒙的ArkTs写出来啊
- ¥30 websocket服务端多线程通信