WoocommerceWordpress Tricks

Woocommerce get order total on daily basis

Woocommerce get order total on daily basis

woocommerce
353Views

Hello to all, welcome to therichpost.com. In this post, I am sharing the code for, how to get Woocommerce get order total on daily basis? 

Woocommerce is the best e-commerce plugin for shopping websites.

Here is the working code for Woocommerce get order total on daily basis:
// functions.php file code
function get_daily_purchases_total(){
    global $wpdb;

    return $wpdb->get_var( "
        SELECT DISTINCT SUM(pm.meta_value)
        FROM {$wpdb->prefix}posts as p
        INNER JOIN {$wpdb->prefix}postmeta as pm ON p.ID = pm.post_id
        WHERE p.post_type LIKE 'shop_order'
        AND p.post_status IN ('wc-processing','wc-completed')
        AND UNIX_TIMESTAMP(p.post_date) >= (UNIX_TIMESTAMP(NOW()) - (86400))
        AND pm.meta_key LIKE '_order_total'
    " );
}

//Use in template file:
<?php echo '<p>Total purchased of the day: ' . get_daily_purchases_total() . '</p>'; ?>

 If you have any query related to this post, then please comment or email me.

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

Positive SSL