WoocommerceWordpress Tricks

How to get woocommerce products order status count with wordpress custom post query?

Get woocommerce products order status count with wordpress custom post query

Views

Hello, welcome to therichpost.com. In this post, I will tell you, How to get woocommerce products order status count with wordpress custom post query? WordPress is the best cms. WordPress hooks(add_action, add_filter) give us the power to edit or change the code without interruption into the files and this is the best thing about wordpress. Now I am going to tell you how the hooks work.

In this post, I am getting product order status count like product order status processing, cancelled, completed.

Here is the code and you need to add this into your theme’s functions.php file:

function get_orders_count_from_status( $status ){
    global $wpdb;

    // We add 'wc-' prefix when is missing from order staus
    $status = 'wc-' . str_replace('wc-', '', $status);

    return $wpdb->get_var("
        SELECT count(ID)  FROM {$wpdb->prefix}posts WHERE post_status LIKE '$status' AND `post_type` LIKE 'shop_order'
    ");
}

 Here is the code to get order status count and you can this into your any theme’s template file:

<?php echo get_orders_count_from_status( "processing" ); ?>

 Now you are done and if you have query related to this post or you want to do some more with this code then please do comment below and I will come with wordpress hooks.

 

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