Merge pull request #4847 from kloon/master
Add email lookup to customers endpoint, try at #4845
This commit is contained in:
commit
5094d2174a
|
@ -70,6 +70,11 @@ class WC_API_Customers extends WC_API_Resource {
|
||||||
array( array( $this, 'get_customer' ), WC_API_SERVER::READABLE ),
|
array( array( $this, 'get_customer' ), WC_API_SERVER::READABLE ),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# GET /customers/<email>
|
||||||
|
$routes[ $this->base . '/email/(?P<email>.+)' ] = array(
|
||||||
|
array( array( $this, 'get_customer_by_email' ), WC_API_SERVER::READABLE ),
|
||||||
|
);
|
||||||
|
|
||||||
# GET /customers/<id>/orders
|
# GET /customers/<id>/orders
|
||||||
$routes[ $this->base . '/(?P<id>\d+)/orders' ] = array(
|
$routes[ $this->base . '/(?P<id>\d+)/orders' ] = array(
|
||||||
array( array( $this, 'get_customer_orders' ), WC_API_SERVER::READABLE ),
|
array( array( $this, 'get_customer_orders' ), WC_API_SERVER::READABLE ),
|
||||||
|
@ -177,6 +182,28 @@ class WC_API_Customers extends WC_API_Resource {
|
||||||
return array( 'customer' => apply_filters( 'woocommerce_api_customer_response', $customer_data, $customer, $fields, $this->server ) );
|
return array( 'customer' => apply_filters( 'woocommerce_api_customer_response', $customer_data, $customer, $fields, $this->server ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the customer for the given email
|
||||||
|
*
|
||||||
|
* @since 2.2
|
||||||
|
* @param string $email the customer email
|
||||||
|
* @param string $fields
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function get_customer_by_email( $email, $fields = null ) {
|
||||||
|
|
||||||
|
if ( is_email( $email ) ) {
|
||||||
|
$customer = get_user_by( 'email', $email );
|
||||||
|
if ( ! is_object( $customer ) ) {
|
||||||
|
return new WP_Error( 'woocommerce_api_invalid_customer_email', __( 'Invalid customer Email', 'woocommerce' ), array( 'status' => 404 ) );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return new WP_Error( 'woocommerce_api_invalid_customer_email', __( 'Invalid customer Email', 'woocommerce' ), array( 'status' => 404 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->get_customer( $customer->ID, $fields );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the total number of customers
|
* Get the total number of customers
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue