Load WooCommerce countries for segment form
[MAILPOET-3226]
This commit is contained in:
committed by
Veljko V
parent
b54eb9af41
commit
173a4a124c
@@ -19,6 +19,11 @@ interface SegmentFormDataWindow extends Window {
|
||||
name: string;
|
||||
}[];
|
||||
|
||||
mailpoet_woocommerce_countries: {
|
||||
code: string;
|
||||
name: string;
|
||||
}[];
|
||||
|
||||
mailpoet_newsletters_list: {
|
||||
sent_at: string;
|
||||
subject: string;
|
||||
@@ -39,4 +44,5 @@ export const SegmentFormData = {
|
||||
wordpressRoles: window.wordpress_editable_roles_list,
|
||||
canUseWooSubscriptions: window.mailpoet_can_use_woocommerce_subscriptions,
|
||||
wooCurrencySymbol: window.mailpoet_woocommerce_currency_symbol,
|
||||
wooCountries: window.mailpoet_woocommerce_countries,
|
||||
};
|
||||
|
@@ -90,6 +90,13 @@ class Segments {
|
||||
$data['products'] = $this->wpPostListLoader->getProducts();
|
||||
$data['subscription_products'] = $this->wpPostListLoader->getSubscriptionProducts();
|
||||
$data['is_woocommerce_active'] = $this->woocommerceHelper->isWooCommerceActive();
|
||||
$wcCountries = $this->woocommerceHelper->isWooCommerceActive() ? $this->woocommerceHelper->getCountries() : [];
|
||||
$data['woocommerce_countries'] = array_map(function ($code, $name) {
|
||||
return [
|
||||
'name' => $name,
|
||||
'code' => $code,
|
||||
];
|
||||
}, array_keys($wcCountries), $wcCountries);
|
||||
$data['can_use_woocommerce_subscriptions'] = $this->segmentDependencyValidator->canUseDynamicFilterType(
|
||||
DynamicSegmentFilterData::TYPE_WOOCOMMERCE_SUBSCRIPTION
|
||||
);
|
||||
|
@@ -64,4 +64,8 @@ class Helper {
|
||||
$htmlPrice = $this->wcPrice($price, $args);
|
||||
return html_entity_decode(strip_tags($htmlPrice));
|
||||
}
|
||||
|
||||
public function getCountries(): array {
|
||||
return (new \WC_Countries)->get_countries() ?? [];
|
||||
}
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@
|
||||
var is_woocommerce_active = <%= json_encode(is_woocommerce_active) %>;
|
||||
var mailpoet_can_use_woocommerce_subscriptions = <%= json_encode(can_use_woocommerce_subscriptions) %>;
|
||||
var mailpoet_woocommerce_currency_symbol = <%= json_encode(woocommerce_currency_symbol) %>;
|
||||
var mailpoet_woocommerce_countries = <%= json_encode(woocommerce_countries) %>;
|
||||
|
||||
</script>
|
||||
<% endblock %>
|
||||
|
Reference in New Issue
Block a user