Ke.
Ke.

Reputation: 2586

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.

Upvotes: 20

Views: 64913

Answers (3)

optimiertes
optimiertes

Reputation: 4212

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

Upvotes: 31

devugur
devugur

Reputation: 1499

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

Upvotes: 9

rnevius
rnevius

Reputation: 27102

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

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

Upvotes: 21

Related Questions