WC_Email::send_notification
Send the email notification when enabled and a recipient is available.
This is the standard helper used by trigger() methods. It checks whether the email is enabled and whether a recipient address exists, fires appropriate action hooks for the disabled or skipped outcome, and otherwise delegates to send() with the standard content parameters.
Subclasses that intentionally bypass the enabled check (e.g. manually-triggered invoice emails, POS receipts) should NOT call this method and should continue to call send() directly.
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_notification(): bool;
Changelog
| Since 10.9.0 | Introduced. |
WC_Email::send_notification() WC Email::send notification code WC 10.9.1
protected function send_notification(): bool {
if ( ! $this->is_enabled() ) {
/**
* Fires when a transactional email is not sent because the email type is disabled.
*
* @since 10.9.0
*
* @param string $email_id The email type ID (e.g. `customer_processing_order`).
* @param WC_Email $email The WC_Email instance.
*/
do_action( 'woocommerce_email_disabled', $this->id, $this );
return false;
}
$recipient = $this->get_recipient();
if ( ! $recipient ) {
/**
* Fires when a transactional email is not sent for a reason other than being disabled.
*
* The $reason parameter identifies why the email was not sent:
* - WC_Email::SKIP_REASON_NO_RECIPIENT: No recipient address was available at send time.
*
* @since 10.9.0
*
* @param string $reason Short identifier for why the email was skipped.
* @param string $email_id The email type ID.
* @param WC_Email $email The WC_Email instance.
*/
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()
);
}