Woo-commerce - get_date_created()- is giving null value

Viewed 118
    $orders=wc_get_orders( array( 'numberposts' => -1,'orderby'=>'date','order'=>'ASC'));
    foreach($orders as $order) {

        $order_id = $order->id;
        $detail = wc_get_order( $order_id );
        $order_status = $detail->get_status();
        $od = $detail->get_date_created(); 
    }

i am trying to get "order-created-date" but its giving me null value. 

is there anything wrong in my code? can i get some help please !

1 Answers

This should be pretty easy. Try this.

$orders = wc_get_orders( array( 'numberposts' => -1,'orderby'=>'date','order'=>'ASC'));

foreach($orders as $order) {
    $order_status = $order->get_status();
    $od = $order->get_date_created();
}

No need to get ID and then again call for orders object.


I would recommend not to use 'numberposts' => -1 as its a performance nightmare. You can learn more about that here : https://10up.github.io/Engineering-Best-Practices/php/#performance

Related