Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the order date, in WooCommerce?

I can see inside class-wc-admin-cpt-shop_order.php there 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 ...

Because WooCommerce uses wp_posts to store the data, can I assume that the post_date field is the correct one to use?

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.

like image 802
Ke. Avatar asked Jul 31 '15 12:07

Ke.


2 Answers

// 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/


Additionally

$order->get_date_created();

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

enter image description here

like image 104
optimiertes Avatar answered Oct 03 '22 20:10

optimiertes


You can use the WC_Order object, if you have the order ID:

$order = new WC_Order($order_id);
$order_date = $order->order_date;
like image 41
rnevius Avatar answered Oct 03 '22 22:10

rnevius