Woocommerce get order total on daily basis

woocommerce

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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.