Forum Replies Created

Viewing 1 replies (of 1 total)
  • If you use it to extends customer class, i t would be easier to extends WC_REST_Customers_Controller

    with extends a class you don’t need to rewrite all public functions which is exact match with the parent class.

    In my case i only need to disable user permissions so every one can register through my app, so myy code is only

    include_once WP_PLUGIN_DIR . '/woocommerce/includes/abstracts/abstract-wc-rest-controller.php';
    include_once WP_PLUGIN_DIR . '/woocommerce/includes/api/class-wc-rest-customers-controller.php';
    /**
     * Create Customers
     */
    class ES_REST_Customers_Controller extends WC_REST_Customers_Controller {
    
    	public function __construct() {
    		$this->namespace = 'es/v1';
    		$this->rest_base = 'customers';
    	}
    
    	public function register_routes() {
    
    		parent::register_routes();
    	}
    
    	/**
    	 * Check if a given request has access create customers.
    	 *
    	 * @param  WP_REST_Request $request Full details about the request.
    	 * @return boolean
    	 */
    	public function create_item_permissions_check( $request ) {
    		// if ( ! wc_rest_check_user_permissions( 'create' ) ) {
    		// 	return new WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
    		// }
    
    		return true;
    	}
    }
Viewing 1 replies (of 1 total)