WC_Privacy_Erasers::customer_data_eraser()
Finds and erases customer data by email address.
Method of the class: WC_Privacy_Erasers{}
Hooks from the method
Return
Array
. An array of personal data in name value pairs
Usage
$result = WC_Privacy_Erasers::customer_data_eraser( $email_address, $page );
- $email_address(string) (required)
- The user email address.
- $page(int) (required)
- Page.
Changelog
Since 3.4.0 | Introduced. |
WC_Privacy_Erasers::customer_data_eraser() WC Privacy Erasers::customer data eraser code WC 7.5.1
public static function customer_data_eraser( $email_address, $page ) { $response = array( 'items_removed' => false, 'items_retained' => false, 'messages' => array(), 'done' => true, ); $user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data. if ( ! $user instanceof WP_User ) { return $response; } $customer = new WC_Customer( $user->ID ); if ( ! $customer ) { return $response; } $props_to_erase = apply_filters( 'woocommerce_privacy_erase_customer_personal_data_props', array( 'billing_first_name' => __( 'Billing First Name', 'woocommerce' ), 'billing_last_name' => __( 'Billing Last Name', 'woocommerce' ), 'billing_company' => __( 'Billing Company', 'woocommerce' ), 'billing_address_1' => __( 'Billing Address 1', 'woocommerce' ), 'billing_address_2' => __( 'Billing Address 2', 'woocommerce' ), 'billing_city' => __( 'Billing City', 'woocommerce' ), 'billing_postcode' => __( 'Billing Postal/Zip Code', 'woocommerce' ), 'billing_state' => __( 'Billing State', 'woocommerce' ), 'billing_country' => __( 'Billing Country / Region', 'woocommerce' ), 'billing_phone' => __( 'Billing Phone Number', 'woocommerce' ), 'billing_email' => __( 'Email Address', 'woocommerce' ), 'shipping_first_name' => __( 'Shipping First Name', 'woocommerce' ), 'shipping_last_name' => __( 'Shipping Last Name', 'woocommerce' ), 'shipping_company' => __( 'Shipping Company', 'woocommerce' ), 'shipping_address_1' => __( 'Shipping Address 1', 'woocommerce' ), 'shipping_address_2' => __( 'Shipping Address 2', 'woocommerce' ), 'shipping_city' => __( 'Shipping City', 'woocommerce' ), 'shipping_postcode' => __( 'Shipping Postal/Zip Code', 'woocommerce' ), 'shipping_state' => __( 'Shipping State', 'woocommerce' ), 'shipping_country' => __( 'Shipping Country / Region', 'woocommerce' ), 'shipping_phone' => __( 'Shipping Phone Number', 'woocommerce' ), ), $customer ); foreach ( $props_to_erase as $prop => $label ) { $erased = false; if ( is_callable( array( $customer, 'get_' . $prop ) ) && is_callable( array( $customer, 'set_' . $prop ) ) ) { $value = $customer->{"get_$prop"}( 'edit' ); if ( $value ) { $customer->{"set_$prop"}( '' ); $erased = true; } } $erased = apply_filters( 'woocommerce_privacy_erase_customer_personal_data_prop', $erased, $prop, $customer ); if ( $erased ) { /* Translators: %s Prop name. */ $response['messages'][] = sprintf( __( 'Removed customer "%s"', 'woocommerce' ), $label ); $response['items_removed'] = true; } } $customer->save(); /** * Allow extensions to remove data for this customer and adjust the response. * * @since 3.4.0 * @param array $response Array response data. Must include messages, num_items_removed, num_items_retained, done. * @param WC_Order $order A customer object. */ return apply_filters( 'woocommerce_privacy_erase_personal_data_customer', $response, $customer ); }