【发布时间】:2019-12-27 10:01:31
【问题描述】:
我正在使用 "How can I get the latest order id in Woocommerce" 答案代码,它通过自定义函数 get_last_order_id() 返回最后一个订单。
这是我获取订单商品的代码尝试:
<?php
$latest_order_id = get_last_order_id(); // Last order ID
$order = wc_get_order( $latest_order_id ); // Get an instance of the WC_Order object
$order_details = $order->get_data(); // Get the order data in an array
$order_status = esc_html( wc_get_order_status_name( $order->get_status() ) );
$order_items = $order_details['line_items'];
?>
然后我在这段代码中使用这个:
<div class="row last-order">
<div class="col-md-7">
<ul>
<?php
foreach ($order_items as $product_name) { ?>
<li><?php echo $product_name['name']; ?></li>
<?php
}
?>
</ul>
</div>
<div class="col-md-4 order-status-box">
<h6 class="status"><?php echo $order_status; ?></h6>
<i class="fas fa-chevron-down icon"></i>
</div>
</div>
我想获得当前客户的最后一个订单。如何更改自定义函数get_last_order_id() 以获取当前客户的最后一个订单?
除了当前用户的最新订单外,我还想收到我的购物车中的内容。
【问题讨论】:
-
在 WHERE 子句中包含 post_author 的条件 then ...?
-
谢谢现在更好@LoicTheAztec
标签: php wordpress woocommerce metadata orders