Categories

Saturday, April 20, 2024
#919814419350 therichposts@gmail.com
WoocommerceWordpress Tricks

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

How to add custom meta title and meta description in Wordpress?

Get woocommerce products order status count with wordpress custom post query

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.

 

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

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