Use enums for countries

[MAILPOET-5169]
This commit is contained in:
Jan Jakes
2023-06-15 13:57:44 +02:00
committed by Aschepikov
parent a3cfeea552
commit 0199786a0e
2 changed files with 54 additions and 12 deletions

View File

@@ -79,11 +79,14 @@ class OrderFieldsFactory {
),
new Field(
'woocommerce:order:billing-country',
Field::TYPE_STRING,
Field::TYPE_ENUM,
__('Billing country', 'mailpoet'),
function (OrderPayload $payload) {
return $payload->getOrder()->get_billing_country();
}
},
[
'options' => $this->getBillingCountryOptions(),
]
),
new Field(
'woocommerce:order:shipping-company',
@@ -127,11 +130,14 @@ class OrderFieldsFactory {
),
new Field(
'woocommerce:order:shipping-country',
Field::TYPE_STRING,
Field::TYPE_ENUM,
__('Shipping country', 'mailpoet'),
function (OrderPayload $payload) {
return $payload->getOrder()->get_shipping_country();
}
},
[
'options' => $this->getShippingCountryOptions(),
]
),
new Field(
'woocommerce:order:created-date',
@@ -259,6 +265,22 @@ class OrderFieldsFactory {
);
}
private function getBillingCountryOptions(): array {
$options = [];
foreach (WC()->countries->get_allowed_countries() as $code => $name) {
$options[] = ['id' => $code, 'name' => $name];
}
return $options;
}
private function getShippingCountryOptions(): array {
$options = [];
foreach (WC()->countries->get_shipping_countries() as $code => $name) {
$options[] = ['id' => $code, 'name' => $name];
}
return $options;
}
private function getOrderPaymentOptions(): array {
$gateways = WC()->payment_gateways()->get_available_payment_gateways();
$options = [];