wordpress 如何在 WooCommerce 中获取订单日期?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31746767/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 11:07:41  来源:igfitidea点击:

How can I get the order date, in WooCommerce?

wordpresswoocommerce

提问by Ke.

I can see inside class-wc-admin-cpt-shop_order.phpthere are some functions that are pulling together the order information for display in WooCommerce. However, I don't see anywhere where the date can be used ...

我可以看到里面class-wc-admin-cpt-shop_order.php有一些功能将订单信息汇总在一起以在 WooCommerce 中显示。但是,我没有看到可以使用日期的任何地方......

Because WooCommerce uses wp_poststo store the data, can I assume that the post_date fieldis the correct one to use?

因为 WooCommerce 用于wp_posts存储数据,所以我可以假设使用的post_date field是正确的吗?

Also, anyone know whether there is a function in WooCommerce to get this, or whether there is a way of getting the date to come out in class-wc-admin-cpt-shop_order.php.

此外,任何人都知道 WooCommerce 中是否有一个功能可以得到这个,或者是否有办法让日期出现在class-wc-admin-cpt-shop_order.php.

回答by rnevius

You can use the WC_Orderobject, if you have the order ID:

如果您有订单 ID,则可以使用WC_Order对象:

$order = new WC_Order($order_id);
$order_date = $order->order_date;

回答by user5510975

Order properties should not be accessed directly. Best way is $order->get_date_completed()

不应直接访问订单属性。最好的办法是$order->get_date_completed()

回答by optimiertes

// Get $order object from order ID 
$order = wc_get_order( $order_id );

// Get Order Dates
$order->get_date_created();
$order->get_date_modified();
$order->get_date_completed();
$order->get_date_paid();

Source: https://businessbloomer.com/woocommerce-easily-get-order-info-total-items-etc-from-order-object/

资料来源:https: //businessbloomer.com/woocommerce-easily-get-order-info-total-items-etc-from-order-object/



Additionally

此外

$order->get_date_created();

Is the "order date", which you can change within WooCommerce ("Edit Order")

是“订单日期”,您可以在 WooCommerce 中更改(“编辑订单”)

enter image description here

在此处输入图片说明