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.
Recent Comments