Fatal error wp_query, Class not found, fatal error wc_order, fatal error of wordpress

 

Keep the function under a hook in wordpress where you use the wp_query or any wp class

 

Like 


add_action('admin_init', 'adminEventOperation');
function adminEventOperation(){
    
    $order_statuses = array('wc-completed', 'wc-processing');
        $args = array(
            'limit' => 1,
            'return' => '*',
            'status' => $order_statuses,
            
        );
        $orders = wc_get_orders($args);
        foreach($orders as $order){
            echo 'Hello order ',$order;
        }
}