Automattic\WooCommerce\Admin\API

MobileAppQRLogin::maybe_send_sign_in_notification_emailprivateWC 1.0

Send the merchant a transactional email summarizing a successful QR sign-in, unless they (or a site owner) opt out via the woocommerce_qr_login_should_send_signin_email

Wrapped so a misconfigured mailer cannot break the exchange path. Mailer false returns and exceptions are logged, but delivery never blocks the API response.

Method of the class: MobileAppQRLogin{}

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->maybe_send_sign_in_notification_email( $user, $consumed_record ): void;
$user(WP_User) (required)
The user who minted the token (recipient).
$consumed_record(array) (required)
.

MobileAppQRLogin::maybe_send_sign_in_notification_email() code WC 11.0.1

private function maybe_send_sign_in_notification_email( \WP_User $user, array $consumed_record ): void {
	/**
	 * Filter whether to send the QR sign-in notification email.
	 *
	 * Default: true. Return false to suppress the send for a specific
	 * user, environment (e.g. staging), or test run.
	 *
	 * @since 10.9.0
	 *
	 * @param bool                 $should_send     Whether to send the email.
	 * @param \WP_User             $user            The user who minted the QR token.
	 * @param array<string, mixed> $consumed_record The consumed record about to be emailed (keys: consumed_at, user_id, ap_uuid, ap_name, device).
	 */
	$should_send = (bool) apply_filters(
		'woocommerce_qr_login_should_send_signin_email',
		true,
		$user,
		$consumed_record
	);

	if ( ! $should_send ) {
		return;
	}

	try {
		if ( ! $this->send_sign_in_notification_email( $user, $consumed_record ) ) {
			wc_get_logger()->warning(
				sprintf(
					'QR sign-in notification email failed for user %d: wp_mail returned false',
					$user->ID
				),
				array( 'source' => 'mobile-app-qr-login' )
			);
		}
	} catch ( \Throwable $e ) {
		// Don't surface mailer failures to the exchange response — the
		// merchant already has the API result, and the email is best-effort.
		// Log instead so a misconfigured mailer is observable rather than
		// invisible. Catch \Throwable so an \Error from the mailer also
		// stays out of the exchange path.
		wc_get_logger()->warning(
			sprintf(
				'QR sign-in notification email failed for user %d: %s',
				$user->ID,
				$e->getMessage()
			),
			array( 'source' => 'mobile-app-qr-login' )
		);
	}
}