diff --git a/lib/AdminPages/Pages/Segments.php b/lib/AdminPages/Pages/Segments.php index d83def979e..4d5d8c5de2 100644 --- a/lib/AdminPages/Pages/Segments.php +++ b/lib/AdminPages/Pages/Segments.php @@ -81,6 +81,7 @@ class Segments { $data['product_categories'] = $this->wpPostListLoader->getWooCommerceCategories(); $data['products'] = $this->wpPostListLoader->getProducts(); + $data['subscription_products'] = $this->wpPostListLoader->getSubscriptionProducts(); $data['is_woocommerce_active'] = $this->woocommerceHelper->isWooCommerceActive(); $this->pageRenderer->displayPage('segments.html', $data); diff --git a/lib/WP/AutocompletePostListLoader.php b/lib/WP/AutocompletePostListLoader.php index 645b64cb93..9719c54c9f 100644 --- a/lib/WP/AutocompletePostListLoader.php +++ b/lib/WP/AutocompletePostListLoader.php @@ -21,6 +21,18 @@ class AutocompletePostListLoader { return $this->formatPosts($products); } + public function getSubscriptionProducts() { + $products = $this->wp->getResultsFromWpDb( + "SELECT `ID`, `post_title` FROM {$this->wp->getWPTableName('posts')} AS p + INNER JOIN {$this->wp->getWPTableName('term_relationships')} AS trel ON trel.object_id = p.id + INNER JOIN {$this->wp->getWPTableName('term_taxonomy')} AS ttax ON ttax.term_taxonomy_id = trel.term_taxonomy_id + INNER JOIN {$this->wp->getWPTableName('terms')} AS t ON ttax.term_id = t.term_id AND t.slug IN ('subscription', 'variable-subscription') + WHERE `p`.`post_type` = %s ORDER BY `post_title` ASC;", + 'product' + ); + return $this->formatPosts($products); + } + public function getWooCommerceCategories() { return $this->formatTerms($this->wp->getCategories(['taxonomy' => 'product_cat', 'orderby' => 'name'])); } diff --git a/views/segments.html b/views/segments.html index 812beabfad..6b7ad5b49c 100644 --- a/views/segments.html +++ b/views/segments.html @@ -26,6 +26,7 @@ var mailpoet_newsletters_list = <%= json_encode(newsletters_list) %>; var mailpoet_product_categories = <%= json_encode(product_categories) %>; var mailpoet_products = <%= json_encode(products) %>; + var mailpoet_subscription_products = <%= json_encode(subscription_products) %>; var is_woocommerce_active = <%= json_encode(is_woocommerce_active) %>;