1
0
mirror of synced 2025-01-29 22:31:42 +03:00

Add validate method for address

This commit is contained in:
Dima Uryvskiy 2020-12-22 11:58:35 +03:00 committed by GitHub
parent ccdc39ce05
commit d9c31e8871
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -81,6 +81,27 @@ abstract class WC_Retailcrm_Abstracts_Address extends WC_Retailcrm_Abstracts_Dat
return $this;
}
/**
* Validate address
*
* @param array $address
*
* @return bool
*/
public function validateAddress($address)
{
if (empty($address['country']) ||
empty($address['state']) ||
empty($address['postcode']) ||
empty($address['city']) ||
empty($address['address_1'])
) {
return false;
}
return true;
}
/**
* Returns address from order. Respects fallback_to_billing parameter.
*
@ -91,7 +112,7 @@ abstract class WC_Retailcrm_Abstracts_Address extends WC_Retailcrm_Abstracts_Dat
protected function getOrderAddress($order)
{
$orderAddress = $order->get_address($this->address_type);
$checkEmptyArray = array_filter($orderAddress);
$checkEmptyArray = $this->validateAddress($orderAddress) ? array_filter($orderAddress) : array();
if (empty($checkEmptyArray) && $this->address_type === self::ADDRESS_TYPE_BILLING && $this->fallback_to_shipping) {
$orderAddress = $order->get_address(self::ADDRESS_TYPE_SHIPPING);