0

Here is my code:

function woo_delete_customer(){
    $customer = new WC_Customer(get_current_user_id());
  $val =  $customer -> delete();
   if($val){
       $customer -> save();
       $data = [];
       $data['Status'] = 'Customer was successfully deleted';
       return new WP_REST_Response( $data, 200 );
   }
   else{
       new WP_Error(
            'woo_deleting_problems',
            'Can\'t delete customer!',
            array(
                'status' => 403,
            )
        );
   }

}

And here is my logs:

2019-11-16T05:29:23+00:00 CRITICAL Call to undefined function wp_delete_user() in /home/test.com/public_html/wp-content/plugins/woocommerce/includes/data-stores/class-wc-customer-data-store.php on line 235

Please help me!((

1

Welcome!

You need to include 'wp-admin/includes/user.php' before calling wp_delete_user function. The reason is, it is an admin functionality and it is not available everywhere in code.

In Your case, just put the following line of code at the very beginning of the function.

require_once ABSPATH . 'wp-admin/includes/user.php';
  • Thanks for your response!)) But this function doesn't delete current customer from DB. But thanks, I'll mark your answer as correct! – Johny Deph Nov 16 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.