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
CodePudding user response:
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.