diff --git a/.github/workflows/testing-integration.yml b/.github/workflows/testing-integration.yml index 2c8f1b61..0da75867 100644 --- a/.github/workflows/testing-integration.yml +++ b/.github/workflows/testing-integration.yml @@ -43,7 +43,9 @@ jobs: name: WordPress ${{ matrix.wordpress }} on PHP ${{ matrix.php }} steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 + with: + ref: ${{ github.ref }} - name: Build "testing" Docker Image run: | diff --git a/includes/data/mutation/class-checkout-mutation.php b/includes/data/mutation/class-checkout-mutation.php index b54960b6..3aa20cde 100644 --- a/includes/data/mutation/class-checkout-mutation.php +++ b/includes/data/mutation/class-checkout-mutation.php @@ -219,7 +219,7 @@ class Checkout_Mutation { * @return bool */ protected static function clear_customer_address( $type = 'billing' ) { - if ( 'billing' !== $type || 'shipping' !== $type ) { + if ( 'billing' !== $type && 'shipping' !== $type ) { return false; } diff --git a/includes/mutation/class-customer-update.php b/includes/mutation/class-customer-update.php index a562b8fc..fd7cbcdd 100644 --- a/includes/mutation/class-customer-update.php +++ b/includes/mutation/class-customer-update.php @@ -109,14 +109,6 @@ class Customer_Update { // Create customer object. $customer = ! $session_only ? new WC_Customer( $payload['id'] ) : \WC()->customer; - // Set billing address. - if ( ! empty( $customer_args['billing'] ) ) { - foreach ( $customer_args['billing'] as $prop => $value ) { - $setter = 'set_billing_' . $prop; - $customer->{$setter}( $value ); - } - } - // Copy billing address as shipping address. if ( ! empty( $input['shippingSameAsBilling'] ) && $input['shippingSameAsBilling'] ) { $customer_args['shipping'] = array_merge( @@ -125,11 +117,22 @@ class Customer_Update { ); } - // Set shipping address. - if ( ! empty( $customer_args['shipping'] ) ) { - foreach ( $customer_args['shipping'] as $prop => $value ) { - $setter = 'set_shipping_' . $prop; - $customer->{$setter}( $value ); + // Update customer fields. + foreach ( $customer_args as $prop => $value ) { + + // If field group like 'shipping' or 'billing'. + if ( ! empty( $value ) && \is_array( $value ) ) { + + // Check if group field has set function and assigns new value. + foreach ( $value as $field => $field_value ) { + if ( is_callable( array( $customer, "set_{$prop}_{$field}") ) ) { + $customer->{"set_{$prop}_{$field}"}( $field_value ); + } + } + + // If field has set function and assigns new value. + } elseif ( is_callable( array( $customer, "set_{$prop}" ) ) ) { + $customer->{"set_{$prop}"}( $value ); } } diff --git a/tests/_support/Helper/crud-helpers/includes/class-dummy.php b/tests/_support/Helper/crud-helpers/includes/class-dummy.php index 4e7a0af3..b950ae36 100644 --- a/tests/_support/Helper/crud-helpers/includes/class-dummy.php +++ b/tests/_support/Helper/crud-helpers/includes/class-dummy.php @@ -177,7 +177,7 @@ class Dummy { } public function lastname() { - $list = explode(",","Smith,Johnson,Williams,Jones,Brown,Davis,Miller,Wilson,Moore,Taylor,Anderson,Thomas,Jackson,White,Harris,Martin,Thompson,Garcia,Martinez,Robinson,Clark,Rodriguez,Lewis,Lee,Walker,Hall,Allen,Young,Hernandez,King,Wright,Lopez,Hill,Scott,Green,Adams,Baker,Gonzalez,Nelson,Carter,Mitchell,Perez,Roberts,Turner,Phillips,Campbell,Parker,Evans,Edwards,Collins"); + $list = explode(",","Smith,Johnson,Williams,Jones,Brown,Davis,Miller,Wilson,Moore,Taylor,Anderson,Thomas,Jackson,White,Harris,Martin,Thompson,Garcia,Martinez,Robinson,Clark,Rodriguez,Lewis,Lee,Walker,Hall,Allen,Young,Hernandez,King,Wright,Lopez,Hill,Scott,Green,Adams,Baker,Gonzalez,Nelson,Carter,Mitchell,Perez,Roberts,Turner,Phillips,Campbell,Parker,Evans,Edwards,Collins,Dexter,Dennis,Menace,Jesus,Bart,Homer,Dan,Bub,Sparkster,Yanni"); shuffle($list); return(current($list)); } @@ -189,11 +189,9 @@ class Dummy { } public function username() { - $n = rand(1,50); + $n = rand(1,300); $f = substr($this->firstname(),0,1); - $l = $this->lastname(); - - if ($n <= 30) { $l .= $n; } + $l = $this->lastname() .$n; return(strtolower($f.$l));