simple backend address validation
This commit is contained in:
@@ -40,6 +40,9 @@ class Wiaas_User {
|
||||
|
||||
if (isset($request['deliveryAddress'])){
|
||||
$received_address = json_decode($request['deliveryAddress']);
|
||||
if (!self::validate_address($received_address)){
|
||||
return false;
|
||||
}
|
||||
$profile_addresses = get_user_meta($customer->ID, 'profile_addresses', true) ?: [];
|
||||
|
||||
if ($received_address->id){
|
||||
@@ -84,6 +87,9 @@ class Wiaas_User {
|
||||
|
||||
if (isset($request['billingAddress'])){
|
||||
$received_address = json_decode($request['billingAddress']);
|
||||
if (!self::validate_address($received_address)){
|
||||
return false;
|
||||
}
|
||||
$billing_addresses = get_user_meta($customer->ID, 'billing_addresses', true) ?: [];
|
||||
|
||||
if ($received_address->id){
|
||||
@@ -221,6 +227,25 @@ class Wiaas_User {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if address is valid
|
||||
*
|
||||
* @param $address
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private static function validate_address($address){
|
||||
if (empty($address->city)){
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($address->detailedAddress)){
|
||||
return false;
|
||||
}
|
||||
|
||||
return is_numeric($address->zipCode);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user