• Resolved nerosylius

    (@nerosylius)


    Hello everyone,
    I would like to add some code that i’ve made in a custom plugin.
    It is working fine but the files are in the WordPress root folder.
    When I’m including these files as a plugin, I have an error on wc_get_order_status() function.
    Basically the function where it is called is just getting every order which have the processing status from the last 24h. I am just using wc_get_order_status() to get all statuses of Woocommerce and unset every statuses that I do no care about (completed for example)
    Thank you by advance.

    function get_orders_by_custom_date()
    {
        date_default_timezone_set('Europe/Paris');
        $now = strtotime('now');
        $today =  date("m/d/Y H:i:s", $now);
        $before_today = date('m/d/Y H:i:s', strtotime('-1 day'));
        $order_statuses = wc_get_order_statuses();
    
        unset($order_statuses['wc-pending']);    
        unset($order_statuses['wc-on-hold']);
        unset($order_statuses['wc-cancelled']);
        unset($order_statuses['wc-refunded']);
        unset($order_statuses['wc-failed']);
        // unset($order_statuses['wc-completed']);
    
        $query_args = array(
            'post_type'      => array('shop_order'),
            'post_status'    => array_keys($order_statuses),
            'posts_per_page' => -1,
            'date_query' => array(
                'after'     => $before_today,
                'before'    => $today,
            ),
        );
        $customer_orders = get_posts($query_args);
        return $customer_orders;
    }
    • This topic was modified 3 years ago by nerosylius. Reason: Forgot the code
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Undefined function wc_get_order_statuses()’ is closed to new replies.