Check if there is a customer ID set before calling get_user_by()

This commit is contained in:
Rodrigo Primo 2018-03-09 08:26:13 -03:00
parent 818819d0ff
commit 37ca7faf2e
1 changed files with 2 additions and 2 deletions

View File

@ -140,10 +140,10 @@ class WC_Customer_Data_Store extends WC_Data_Store_WP implements WC_Customer_Dat
* @throws Exception If invalid customer.
*/
public function read( &$customer ) {
$user_object = get_user_by( 'id', $customer->get_id() );
$user_object = $customer->get_id() ? get_user_by( 'id', $customer->get_id() ) : false;
// User object is required.
if ( ! $customer->get_id() || ! $user_object || empty( $user_object->ID ) ) {
if ( ! $user_object || empty( $user_object->ID ) ) {
throw new Exception( __( 'Invalid customer.', 'woocommerce' ) );
}