WC_Customer::save
Overrides the save method to guard against saves with no data changed.
Method of the class: WC_Customer{}
Hooks from the method
Returns
Int.
Usage
$WC_Customer = new WC_Customer(); $WC_Customer->save();
Changelog
| Since 10.9.0 | Introduced. |
WC_Customer::save() WC Customer::save code WC 10.9.3
public function save() {
$customer_id = $this->get_id();
if ( $customer_id ) {
$meta_data = $this->meta_data ?? array();
$props_changed = ! empty( $this->password ) || ! empty( $this->changes );
$state_changed = $props_changed || ! empty( array_filter( $meta_data, static fn( $meta ) => ! $meta->id || ! empty( $meta->get_changes() ) ) );
if ( ! $state_changed ) {
// Backward compatibility: e.g. '( new WC_Customer( $customer_id ) )->save()' as means to trigger integrations.
do_action( 'woocommerce_update_customer', $customer_id, $this ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.HookCommentWrongStyle
return $this->get_id();
}
}
return parent::save();
}