Automattic\WooCommerce\Admin\API\Reports\Customers

DataStore::get_customer_id_by_user_id()public staticWC 1.0

Retrieve a registered customer row id by user_id.

Method of the class: DataStore{}

No Hooks.

Return

false|Int. Customer ID if found, boolean false if not.

Usage

$result = DataStore::get_customer_id_by_user_id( $user_id );
$user_id(string|int) (required)
User ID.

DataStore::get_customer_id_by_user_id() code WC 8.7.0

public static function get_customer_id_by_user_id( $user_id ) {
	global $wpdb;

	$table_name  = self::get_db_table_name();
	$customer_id = $wpdb->get_var(
		$wpdb->prepare(
			// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
			"SELECT customer_id FROM {$table_name} WHERE user_id = %d LIMIT 1",
			$user_id
		)
	);

	return $customer_id ? (int) $customer_id : false;
}