admin管理员组

文章数量:1406926

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/public_html/wp-content/plugins/woocommerce/includes/data-stores/class-wc-customer-data-store.php on line 235

Please help me!((

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/public_html/wp-content/plugins/woocommerce/includes/data-stores/class-wc-customer-data-store.php on line 235

Please help me!((

Share Improve this question asked Nov 16, 2019 at 5:52 Atamyrat BabayevAtamyrat Babayev 1134 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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';

本文标签: phpWCCustomer delete function returns error