Automattic\WooCommerce\Internal\StockNotifications\Frontend

NotificationManagementService::resend_verification_email │ public │ WC 1.0

Send the verification email for a pending notification again.

Pure domain step: checks the status and the rate limit, records the send time, and dispatches the email. Callers own authentication, nonces, notices and redirects.

Method of the class: NotificationManagementService{}

No Hooks.

Returns

true|\WP_Error. True on send, or an error carrying one of the RESEND_ERROR_* codes.

Usage

$NotificationManagementService = new NotificationManagementService();
$NotificationManagementService->resend_verification_email( $notification );
$notification(Notification) (required)
The notification to resend for.

NotificationManagementService::resend_verification_email() code WC 11.2.1

public function resend_verification_email( Notification $notification ) {
	if ( NotificationStatus::PENDING !== $notification->get_status() ) {
		return new \WP_Error( self::RESEND_ERROR_NOT_PENDING, __( 'This notification is already verified or cancelled.', 'woocommerce' ) );
	}

	$last_sent_at = (int) $notification->get_meta( self::LAST_VERIFY_EMAIL_SENT_META );
	if ( $last_sent_at > 0 && ( time() - $last_sent_at ) < self::RESEND_RATE_LIMIT_SECONDS ) {
		return new \WP_Error( self::RESEND_ERROR_RATE_LIMITED, __( 'Please wait a moment before requesting another verification email.', 'woocommerce' ) );
	}

	// Persist the rate-limit timestamp before dispatching the email so two near-simultaneous
	// requests can't both pass the rate-limit check and trigger duplicate sends.
	$notification->update_meta_data( self::LAST_VERIFY_EMAIL_SENT_META, (string) time() );
	$notification->save();

	$this->email_manager->send_verify_email( $notification );

	return true;
}