Add getOrdersCount() to WooCommerce helper

[MAILPOET-1732]
This commit is contained in:
Rostislav Wolny
2019-03-22 11:56:19 +01:00
committed by M. Shull
parent 74bee5ec1e
commit 29e2cebce3
5 changed files with 53 additions and 4 deletions

View File

@@ -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;
});
}
}