Answer the question
In order to leave comments, you need to log in
How to display number of woocommerce orders?
I want to make a note on the site "1,868 orders have been placed on our site."
How to get this number? I didn’t find something in the woocommerce and wordpress API :(
From somewhere it is taken in the admin panel
Answer the question
In order to leave comments, you need to log in
function display_woocommerce_order_count( $atts, $content = null ) {
$args = shortcode_atts( array(
'status' => 'completed',
), $atts );
$statuses = array_map( 'trim', explode( ',', $args['status'] ) );
$order_count = 0;
foreach ( $statuses as $status ) {
if ( 0 !== strpos( $status, 'wc-' ) ) {
$status = 'wc-' . $status;
}
$order_count += wp_count_posts( 'shop_order' )->$status;
}
ob_start();
echo number_format( $order_count );
return ob_get_clean();
}
add_shortcode( 'wc_order_count', 'display_woocommerce_order_count' );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question