I am trying the following code and want to get all orders between dates and print them
$orders = $my_query->posts;
$order = wc_get_order( $order_id );
$order_data = $order->get_data(); // The Order data
$order_id = $order_data['id'];
if ($order_data['date_created']='12-12-2023')
{
echo('Order id-'.$order_id.'---order id end here-----');
}
Getting error Uncaught Error: Call to a member function get_data() on bool
please try to use this code:
$initial_date = yyyy-mm-dd;
$final_date = yyyy-mm-dd;
$orders = wc_get_orders(array(
'limit'=>-1,
'type'=> 'shop_order',
'date_created'=> $initial_date .'...'. $final_date
)
);
$orders should now hold all orders between given dates.
It also works with dates that include hours : minutes : seconds :
$date_a = '2022-08-18 09:45:00';
$date_b = '2022-09-02 19:30:00';
$on_hold_orders = wc_get_orders
(
array
(
'limit' => -1,
'post_type' => 'shop_order',
'status' => 'on-hold',
'date_created' => strtotime($date_a) .'...'. strtotime($date_b)
)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With