WC_Checkout::set_customer_address_fields
Set address field for customer.
Method of the class: WC_Checkout{}
No Hooks.
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->set_customer_address_fields( $field, $key, $data );
- $field(string) (required)
- String to update.
- $key(string) (required)
- Field key.
- $data(array) (required)
- Array of data to get the value from.
Changelog
| Since 3.0.7 | Introduced. |
WC_Checkout::set_customer_address_fields() WC Checkout::set customer address fields code WC 10.7.0
protected function set_customer_address_fields( $field, $key, $data ) {
$billing_value = null;
$shipping_value = null;
if ( isset( $data[ "billing_{$field}" ] ) && is_callable( array( WC()->customer, "set_billing_{$field}" ) ) ) {
$billing_value = $data[ "billing_{$field}" ];
$shipping_value = $data[ "billing_{$field}" ];
}
if ( isset( $data[ "shipping_{$field}" ] ) && is_callable( array( WC()->customer, "set_shipping_{$field}" ) ) ) {
$shipping_value = $data[ "shipping_{$field}" ];
}
if ( ! is_null( $billing_value ) && is_callable( array( WC()->customer, "set_billing_{$field}" ) ) ) {
WC()->customer->{"set_billing_{$field}"}( $billing_value );
}
if ( ! is_null( $shipping_value ) && is_callable( array( WC()->customer, "set_shipping_{$field}" ) ) ) {
WC()->customer->{"set_shipping_{$field}"}( $shipping_value );
}
}