Hide WooCommerce segments when WooCommerce is not active
[MAILPOET-2163]
This commit is contained in:
committed by
Jack Kitterhing
parent
92a85d553b
commit
c1c2d0a102
@ -155,6 +155,24 @@ class Segment extends Model {
|
||||
return $wc_segment;
|
||||
}
|
||||
|
||||
static function shouldShowWooCommerceSegment() {
|
||||
$is_woocommerce_active = class_exists('WooCommerce');
|
||||
$woocommerce_users_count = Subscriber::where('is_woocommerce_user', 1)->count();
|
||||
|
||||
if (!$is_woocommerce_active && $woocommerce_users_count === 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static function getSegmentTypes() {
|
||||
$types = [Segment::TYPE_DEFAULT, Segment::TYPE_WP_USERS];
|
||||
if (Segment::shouldShowWooCommerceSegment()) {
|
||||
$types[] = Segment::TYPE_WC_USERS;
|
||||
}
|
||||
return $types;
|
||||
}
|
||||
|
||||
static function search($orm, $search = '') {
|
||||
return $orm->whereLike('name', '%' . $search . '%');
|
||||
}
|
||||
@ -185,7 +203,7 @@ class Segment extends Model {
|
||||
|
||||
static function getSegmentsWithSubscriberCount($type = self::TYPE_DEFAULT) {
|
||||
$query = self::selectMany([self::$_table . '.id', self::$_table . '.name'])
|
||||
->whereIn('type', [Segment::TYPE_DEFAULT, Segment::TYPE_WP_USERS, Segment::TYPE_WC_USERS])
|
||||
->whereIn('type', Segment::getSegmentTypes())
|
||||
->selectExpr(
|
||||
self::$_table . '.*, ' .
|
||||
'COUNT(IF(' .
|
||||
@ -243,7 +261,7 @@ class Segment extends Model {
|
||||
|
||||
static function listingQuery(array $data = []) {
|
||||
$query = self::select('*');
|
||||
$query->whereIn('type', [Segment::TYPE_DEFAULT, Segment::TYPE_WP_USERS, Segment::TYPE_WC_USERS]);
|
||||
$query->whereIn('type', Segment::getSegmentTypes());
|
||||
if (isset($data['group'])) {
|
||||
$query->filter('groupBy', $data['group']);
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ class Subscriber extends Model {
|
||||
|
||||
$segments = Segment::orderByAsc('name')
|
||||
->whereNull('deleted_at')
|
||||
->whereIn('type', [Segment::TYPE_DEFAULT, Segment::TYPE_WP_USERS, Segment::TYPE_WC_USERS])
|
||||
->whereIn('type', Segment::getSegmentTypes())
|
||||
->findMany();
|
||||
$segment_list = [];
|
||||
$segment_list[] = [
|
||||
|
Reference in New Issue
Block a user