Guest User

Untitled

a guest
Jun 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. function display_woocommerce_order_count( $atts, $content = null ) {
  2. $args = shortcode_atts( array(
  3. 'status' => 'completed',
  4. ), $atts );
  5. $statuses = array_map( 'trim', explode( ',', $args['status'] ) );
  6. $order_count = 0;
  7. foreach ( $statuses as $status ) {
  8. // if we didn't get a wc- prefix, add one
  9. if ( 0 !== strpos( $status, 'wc-' ) ) {
  10. $status = 'wc-' . $status;
  11. }
  12. $order_count += wp_count_posts( 'shop_order' )->$status;
  13. }
  14. ob_start();
  15. echo number_format( $order_count );
  16. return ob_get_clean();
  17. }
  18. add_shortcode( 'wc_order_count', 'display_woocommerce_order_count' );
Add Comment
Please, Sign In to add comment