skip to Main Content

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

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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)
        )
    );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search