Last active
July 5, 2023 10:05
-
-
Save kloon/4951687 to your computer and use it in GitHub Desktop.
WooCommerce add Delete Account button to My Account page This is very dangerous functionality and can cause your whole WordPress installation to break
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Delete Account Functionality | |
add_action( 'woocommerce_after_my_account', 'woo_delete_account_button' ); | |
function woo_delete_account_button() { | |
?> | |
<a href="<?php echo add_query_arg( 'wc-api', 'wc-delete-account', home_url( '/' ) ) ?>" class="button">Delete Account</a> | |
<?php | |
} | |
add_action( 'woocommerce_api_' . strtolower( 'wc-delete-account' ), 'woo_handle_account_delete' ); | |
function woo_handle_account_delete() { | |
// we do not want the admin to delete their account | |
// advised to add more checks here to ensure you delete the correct account. | |
if ( ! is_admin() ) { | |
require('./wp-admin/includes/user.php'); | |
wp_delete_user(get_current_user_id()); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How, before delete user, cancel all orders???