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.

{} Это метод класса: DataStore{}

Хуков нет.

Возвращает

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

Использование

$result = DataStore::get_customer_id_by_user_id( $user_id );
$user_id(строка|int) (обязательный)
User ID.

Код DataStore::get_customer_id_by_user_id() WC 6.6.1

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;
}