Add customer address change action to user profile (#39254)

This commit is contained in:
Barry Hughes 2023-12-07 14:52:36 -08:00 committed by GitHub
commit 030bc4004f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Makes it possible to use existing action hook `woocommerce_customer_save_address` to detect customer address changes made via the admin environment.

View File

@ -212,7 +212,7 @@ if ( ! class_exists( 'WC_Admin_Profile', false ) ) :
$save_fields = $this->get_customer_meta_fields();
foreach ( $save_fields as $fieldset ) {
foreach ( $save_fields as $fieldset_type => $fieldset ) {
foreach ( $fieldset['fields'] as $key => $field ) {
@ -222,6 +222,25 @@ if ( ! class_exists( 'WC_Admin_Profile', false ) ) :
update_user_meta( $user_id, $key, wc_clean( $_POST[ $key ] ) );
}
}
// Skip firing the action for any non-internal fieldset types.
if ( ! in_array( $fieldset_type, array( 'billing', 'shipping' ), true ) ) {
continue;
}
// Fieldset type is an internal address type.
$address_type = $fieldset_type;
/**
* Hook: woocommerce_customer_save_address.
*
* Fires after a customer address has been saved on the user profile admin screen.
*
* @since 8.5.0
* @param int $user_id User ID being saved.
* @param string $address_type Type of address; 'billing' or 'shipping'.
*/
do_action( 'woocommerce_customer_save_address', $user_id, $address_type );
}
}