Add getOrdersCount() to WooCommerce helper
[MAILPOET-1732]
This commit is contained in:
committed by
M. Shull
parent
74bee5ec1e
commit
29e2cebce3
@@ -1,7 +1,20 @@
|
||||
<?php
|
||||
namespace MailPoet\WooCommerce;
|
||||
|
||||
use MailPoet\WP\Functions;
|
||||
|
||||
class Helper {
|
||||
|
||||
/** @var Functions */
|
||||
private $wp;
|
||||
|
||||
function __construct(Functions $wp = null) {
|
||||
if (!$wp) {
|
||||
$wp = Functions::get();
|
||||
}
|
||||
$this->wp = $wp;
|
||||
}
|
||||
|
||||
function isWooCommerceActive() {
|
||||
return class_exists('WooCommerce');
|
||||
}
|
||||
@@ -21,4 +34,11 @@ class Helper {
|
||||
function wcGetProduct($the_product = false) {
|
||||
return wc_get_product($the_product);
|
||||
}
|
||||
|
||||
function getOrdersCount() {
|
||||
$counts = $this->wp->wpCountPosts('shop_order');
|
||||
return array_reduce((array)$counts, function($sum, $count_for_state) {
|
||||
return $sum + (int)$count_for_state;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user