# "Delete My Account" Request in My Account

> Adds a button to the Account details page that sends a personal data erasure request through WordPress's privacy tools, which the customer confirms by email.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, my-account, privacy, gdpr
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-account-deletion-request/

## Code

```php
add_action( 'woocommerce_edit_account_form_end', function () {
    printf(
        '<p class="wpide-delete-account"><a class="button" href="%1$s" onclick="return confirm(%2$s)">%3$s</a></p>',
        esc_url( wp_nonce_url( add_query_arg( 'wpide_erase_request', 1, wc_get_account_endpoint_url( 'edit-account' ) ), 'wpide_erase_request' ) ),
        esc_attr( wp_json_encode( 'We will email you a link to confirm that you want your account and personal data deleted. Continue?' ) ),
        esc_html( 'Request account deletion' )
    );
} );

add_action( 'template_redirect', function () {
    if ( empty( $_GET['wpide_erase_request'] ) || ! is_user_logged_in() ) {
        return;
    }

    if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'wpide_erase_request' ) ) {
        return;
    }

    $request_id = wp_create_user_request( wp_get_current_user()->user_email, 'remove_personal_data' );

    if ( is_wp_error( $request_id ) ) {
        wc_add_notice( 'A deletion request is already pending for your account. Please check your inbox for the confirmation email.', 'notice' );
    } else {
        wp_send_user_request( $request_id );
        wc_add_notice( 'Please check your inbox and click the link to confirm your account deletion request.' );
    }

    wp_safe_redirect( wc_get_account_endpoint_url( 'edit-account' ) );
    exit;
} );
```

## Notes

Requests appear under Tools > Erase Personal Data for you to complete; nothing is deleted automatically.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find ""Delete My Account" Request in My Account" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
