wc_get_customer_avatar_url

Wrapper for @see get_avatar() which doesn't simply return the URL so we need to pluck it from the HTML img tag.

Description

(string) wc_get_customer_avatar_url( (string) $email ); 

Kudos to https://github.com/WP-API/WP-API for offering a better solution.

Returns (string)

the URL to the customer's avatar.

Parameters (1)

0. $email (string)
The customer's email.

Usage

  1. if ( !function_exists( 'wc_get_customer_avatar_url' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-user-functions.php'; 
  3.  
  4. // the customer's email. 
  5. $email = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_get_customer_avatar_url($email); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-user-functions.php  
  1. function wc_get_customer_avatar_url( $email ) { 
  2. $avatar_html = get_avatar( $email ); 
  3.  
  4. // Get the URL of the avatar from the provided HTML. 
  5. preg_match( '/src=["|\'](.+)[\&|"|\']/U', $avatar_html, $matches ); 
  6.  
  7. if ( isset( $matches[1] ) && ! empty( $matches[1] ) ) { 
  8. return esc_url_raw( $matches[1] ); 
  9.  
  10. return null;