-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwoocommerce-display-order-count.php
65 lines (52 loc) · 1.79 KB
/
woocommerce-display-order-count.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* Plugin Name: WooCommerce Display Order Count
* Plugin URI: http://www.skyverge.com/product/woocommerce-display-order-count/
* Description: Adds the [wc_order_count] shortcode to display the total number of orders placed on your site.
* Author: SkyVerge
* Author URI: http://www.skyverge.com/
* Version: 1.1.0
*
* GitHub Plugin URI: bekarice/woocommerce-display-order-count
* GitHub Branch: master
*
* Copyright: (c) 2015-2015 SkyVerge, Inc. (info@skyverge.com)
*
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*
* @package WC-Display-Order-Count
* @author SkyVerge
* @category Admin
* @copyright Copyright (c) 2015-2015, SkyVerge, Inc
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
*
*/
defined( 'ABSPATH' ) or exit;
/**
* Plugin Description
*
* Adds a shortcode to display the total number of orders on your shop (defaults to completed orders)
* The shortcode can accept the optional 'status' attribute to display the total number of orders with the included statuses.
*
* Use [wc_order_count status="completed,pending"] to display the total for completed and processing orders
*
*/
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 we didn't get a wc- prefix, add one
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' );