Add validate method for address
This commit is contained in:
parent
ccdc39ce05
commit
d9c31e8871
@ -81,6 +81,27 @@ abstract class WC_Retailcrm_Abstracts_Address extends WC_Retailcrm_Abstracts_Dat
|
|||||||
return $this;
|
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.
|
* 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)
|
protected function getOrderAddress($order)
|
||||||
{
|
{
|
||||||
$orderAddress = $order->get_address($this->address_type);
|
$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) {
|
if (empty($checkEmptyArray) && $this->address_type === self::ADDRESS_TYPE_BILLING && $this->fallback_to_shipping) {
|
||||||
$orderAddress = $order->get_address(self::ADDRESS_TYPE_SHIPPING);
|
$orderAddress = $order->get_address(self::ADDRESS_TYPE_SHIPPING);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user