WooCommerce Programmatically reset customer password
Question
I’m building a mobile app and need a way to reset the user password through the REST API and I found a hook call woocommerce_customer_reset_password
but not working for me it doesn’t send the reset email to the user
The whole code I made:
/**
* Plugin Name: WooCommerce Reset Password through REST API
* Plugin URI: https://example.com/plugins/the-basics/
* Version: 1.0.0
* Author: Hesham Shawky
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: cars-time-settings
* Domain Path: /languages
*/
function woocommerce_reset_password_endpoint()
{
/**
* route /reset
*/
register_rest_route(
'woocommerce-reset-password',
'reset',
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => 'woocommerce_reset_password',
)
);
}
add_action('rest_api_init', 'woocommerce_reset_password_endpoint');
function woocommerce_reset_password(WP_REST_Request $req) {
$user_email = $req->get_body_params()['email'];
$user = get_user_by('email', $user_email);
// return $user;
if ( $user ) {
do_action( 'woocommerce_customer_reset_password', $user );
return true;
}
return false;
}
0
4 months
0 Answers
23 views
0
Leave an answer
You must login or register to add a new answer .