SHARE
TWEET

Woocommerce echo total number of orders

DesignerEthan Jun 23rd, 2013 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Since woocommerce orders are just a post type I thought it would be interesting to run through the orders to get a total amount of orders. This could be useful for a site selling a limited amount of items and wish to show how many orders have been placed so far. Another example could be to simply have the total in the footer as a trust builder. Sure you could expand the query to only count paid orders etc. */
  2.  
  3.                 $args=array(
  4.                   'post_type' => 'shop_order',
  5.                   'posts_per_page' => -1,
  6.                   );
  7.  
  8.                 $my_query = null;
  9.                 $my_query = new WP_Query($args);
  10.                 if( $my_query->have_posts() ) {
  11.                         $count = 0;
  12.                         while ($my_query->have_posts()) : $my_query->the_post(); {
  13.                                 $count++;
  14.                         }
  15.                         endwhile;
  16.                         echo $count;
  17.                 }
  18.                 wp_reset_query();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top