WC_API_Customers::edit_customer()
Edit a customer
Метод класса: WC_API_Customers{}
Возвращает
Массив|WP_Error
.
Использование
$WC_API_Customers = new WC_API_Customers(); $WC_API_Customers->edit_customer( $id, $data );
- $id(int) (обязательный)
- the customer ID
- $data(массив) (обязательный)
- -
Список изменений
С версии 2.2 | Введена. |
Код WC_API_Customers::edit_customer() WC API Customers::edit customer WC 8.7.0
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() ) ); } }