WC_API_Customers::edit_customer( int $id, array $data )
Edit a customer
Description Description
Parameters Parameters
- $id
-
(Required) the customer ID
- $data
-
(Required)
Return Return
(array|WP_Error)
Source Source
File: includes/legacy/api/v2/class-wc-api-customers.php
public function edit_customer( $id, $data ) { try { if ( ! isset( $data['customer'] ) ) { throw new WC_API_Exception( 'woocommerce_api_missing_customer_data', sprintf( __( 'No %1$s data specified to edit %1$s', 'woocommerce' ), 'customer' ), 400 ); } $data = $data['customer']; // Validate the customer ID. $id = $this->validate_request( $id, 'customer', 'edit' ); // Return the validate error. if ( is_wp_error( $id ) ) { throw new WC_API_Exception( $id->get_error_code(), $id->get_error_message(), 400 ); } $data = apply_filters( 'woocommerce_api_edit_customer_data', $data, $this ); $customer = new WC_Customer( $id ); // Customer email. if ( isset( $data['email'] ) ) { $customer->set_email( $data['email'] ); } // Customer password. if ( isset( $data['password'] ) ) { $customer->set_password( $data['password'] ); } // Update customer data. $this->update_customer_data( $customer->get_id(), $data, $customer ); $customer->save(); do_action( 'woocommerce_api_edit_customer', $customer->get_id(), $data ); return $this->get_customer( $customer->get_id() ); } catch ( Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } }
Changelog Changelog
Version | Description |
---|---|
2.2 | Introduced. |