WC_Email::send_if_recipientprotectedWC 10.9.0

Send the email when a recipient is available, regardless of the enabled setting.

This helper is intended for manually-triggered emails (e.g. invoice resend, POS receipts) that intentionally bypass the enabled/disabled check. It fires woocommerce_email_skipped reason {@see WC_Email::SKIP_REASON_NO_RECIPIENT} when no recipient is available so the outcome is still observable via the EmailLogger, and otherwise delegates to send().

Method of the class: WC_Email{}

Hooks from the method

Returns

true|false. Whether the email was sent successfully.

Usage

// protected - for code of main (parent) or child class
$result = $this->send_if_recipient(): bool;

Changelog

Since 10.9.0 Introduced.

WC_Email::send_if_recipient() code WC 11.0.1

protected function send_if_recipient(): bool {
	$recipient = $this->get_recipient();

	if ( ! $recipient ) {
		/**
		 * Fires when a transactional email is not sent for a reason other than being disabled.
		 *
		 * This action is documented in includes/emails/class-wc-email.php
		 *
		 * @since 10.9.0
		 */
		do_action( 'woocommerce_email_skipped', self::SKIP_REASON_NO_RECIPIENT, $this->id, $this );
		return false;
	}

	return $this->send(
		$recipient,
		$this->get_subject(),
		$this->get_content(),
		$this->get_headers(),
		$this->get_attachments()
	);
}