use new list of countries and adapt backend and frontend to it
This commit is contained in:
@@ -9,7 +9,7 @@ class Wiass_REST_User_API {
|
||||
private static $namespace = 'wiaas';
|
||||
|
||||
public function __construct() {
|
||||
include_once dirname( __FILE__ ) . '/user/class-wiaas-user-profile.php';
|
||||
include_once dirname( __FILE__ ) . '/../class-wiaas-countries.php';
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class Wiass_REST_User_API {
|
||||
}
|
||||
|
||||
public static function get_countries(){
|
||||
$countries = Wiaas_User_Profile::get_list_of_countries();
|
||||
$countries = Wiaas_Countries::get_list_of_countries();
|
||||
|
||||
return new WP_REST_Response($countries);
|
||||
}
|
||||
|
||||
@@ -17,18 +17,21 @@ class Wiaas_Countries {
|
||||
*/
|
||||
private static $available_countries = array(
|
||||
'Sweden' => array(
|
||||
'id' => 1,
|
||||
'name' => 'Sweden',
|
||||
'code' => 'se',
|
||||
'vat' => 9 ,
|
||||
'currency' => 'SEK'
|
||||
),
|
||||
'Denmark' => array(
|
||||
'id' => 2,
|
||||
'name' => 'Denmark',
|
||||
'code' => 'dk',
|
||||
'vat' => 9 ,
|
||||
'currency' => 'DKK'
|
||||
),
|
||||
'Finland' => array(
|
||||
'id' => 3,
|
||||
'name' => 'Finland',
|
||||
'code' => 'fi',
|
||||
'vat' => 9 ,
|
||||
@@ -41,6 +44,24 @@ class Wiaas_Countries {
|
||||
add_action('woocommerce_after_register_taxonomy', array(__CLASS__, 'register_product_countries_taxonomy'));
|
||||
}
|
||||
|
||||
public static function get_list_of_countries(){
|
||||
$result = [];
|
||||
foreach(self::$available_countries as $country){
|
||||
array_push($result, array(
|
||||
'idCountry' => $country['id'],
|
||||
'countryName' => $country['name']
|
||||
));
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function get_country_name_by_id($id){
|
||||
foreach(self::$available_countries as $country){
|
||||
if ($country['id'] == $id) return $country['name'];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers product taxonomy for avaiable countries
|
||||
*/
|
||||
|
||||
@@ -8,7 +8,7 @@ defined( 'ABSPATH' ) || exit;
|
||||
class Wiaas_User {
|
||||
|
||||
public static function init() {
|
||||
include_once dirname( __FILE__ ) . '/user/class-wiaas-user-profile.php';
|
||||
include_once dirname( __FILE__ ) . '/class-wiaas-countries.php';
|
||||
|
||||
add_action('init', array(__CLASS__, 'load_user_organization'));
|
||||
add_action('plugins_loaded', array(__CLASS__, 'remove_default_user_groups'), 30);
|
||||
@@ -45,7 +45,7 @@ class Wiaas_User {
|
||||
if ($received_address->id){
|
||||
$updated = array(
|
||||
'id' => $received_address->id,
|
||||
'countryName' => Wiaas_User_Profile::get_country_name_by_id($received_address->idCountrySelected),
|
||||
'countryName' => Wiaas_Countries::get_country_name_by_id($received_address->idCountrySelected),
|
||||
'deliveryMail' => $received_address->deliveryMail,
|
||||
'idCountrySelected' => $received_address->idCountrySelected,
|
||||
'city' => $received_address->city,
|
||||
@@ -64,7 +64,7 @@ class Wiaas_User {
|
||||
}else{
|
||||
$new_delivery_address = array(
|
||||
'id' => time(),
|
||||
'countryName' => Wiaas_User_Profile::get_country_name_by_id($received_address->idCountrySelected),
|
||||
'countryName' => Wiaas_Countries::get_country_name_by_id($received_address->idCountrySelected),
|
||||
'deliveryMail' => $received_address->deliveryMail,
|
||||
'idCountrySelected' => $received_address->idCountrySelected,
|
||||
'city' => $received_address->city,
|
||||
@@ -89,7 +89,7 @@ class Wiaas_User {
|
||||
if ($received_address->id){
|
||||
$updated = array(
|
||||
'id' => $received_address->id,
|
||||
'countryName' => Wiaas_User_Profile::get_country_name_by_id($received_address->idCountrySelected),
|
||||
'countryName' => Wiaas_Countries::get_country_name_by_id($received_address->idCountrySelected),
|
||||
'deliveryMail' => $received_address->deliveryMail,
|
||||
'idCountrySelected' => $received_address->idCountrySelected,
|
||||
'city' => $received_address->city,
|
||||
@@ -108,7 +108,7 @@ class Wiaas_User {
|
||||
}else{
|
||||
$new_billing_address = array(
|
||||
'id' => time(),
|
||||
'countryName' => Wiaas_User_Profile::get_country_name_by_id($received_address->idCountrySelected),
|
||||
'countryName' => Wiaas_Countries::get_country_name_by_id($received_address->idCountrySelected),
|
||||
'deliveryMail' => $received_address->deliveryMail,
|
||||
'idCountrySelected' => $received_address->idCountrySelected,
|
||||
'city' => $received_address->city,
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
// Exit if accessed directly
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Wiaas_User_Profile {
|
||||
|
||||
const LIST_OF_COUNTRIES = [
|
||||
array(
|
||||
'idCountry' => '1',
|
||||
'countryName' => 'Sweden'
|
||||
),
|
||||
array(
|
||||
'idCountry' => '2',
|
||||
'countryName' => 'Finland'
|
||||
),
|
||||
array(
|
||||
'idCountry' => '3',
|
||||
'countryName' => 'Denmark'
|
||||
)
|
||||
];
|
||||
|
||||
public static function get_list_of_countries(){
|
||||
return self::LIST_OF_COUNTRIES;
|
||||
}
|
||||
|
||||
public static function check_country_id($id){
|
||||
foreach (self::LIST_OF_COUNTRIES as $country){
|
||||
if ($country['idCountry'] === $id) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function get_country_name_by_id($id){
|
||||
foreach(self::LIST_OF_COUNTRIES as $country){
|
||||
if ($country['idCountry'] === $id) return $country['countryName'];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user