Automattic\WooCommerce\Internal\Email
EmailLogger::log_non_send_outcome
Write a log entry for an email that was not sent (disabled or skipped).
Centralises the shared logic for disabled and skipped outcomes so that the context schema (source, email_type, status, reason, recipient, object key) is defined in exactly one place. Future additions (e.g. a correlation_id field) only need to be made here.
Method of the class: EmailLogger{}
Hooks from the method
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->log_non_send_outcome( $email_id, $email, $status, ?string $reason ): void;
- $email_id(string) (required)
- The email type ID.
- $email(WC_Email) (required)
- The WC_Email instance.
- $status(string) (required)
- The outcome status:
'disabled'or'skipped'. - ?string $reason
- .
Default:null
EmailLogger::log_non_send_outcome() EmailLogger::log non send outcome code WC 10.9.1
private function log_non_send_outcome( string $email_id, WC_Email $email, string $status, ?string $reason = null ): void {
/**
* Filter whether to log this transactional email attempt.
*
* This filter is documented in src/Internal/Email/EmailLogger.php
*
* @since 10.9.0
*/
if ( ! apply_filters( 'woocommerce_email_log_enabled', true, $email_id, $email ) ) {
return;
}
$object_context = $this->get_object_context( $email->object );
$object_label = isset( $object_context['type'], $object_context['id'] )
? sprintf( ' for %s #%d', $object_context['type'], $object_context['id'] )
: '';
if ( 'disabled' === $status ) {
$message = sprintf( 'Email "%s"%s not sent: email type is disabled', $email_id, $object_label );
} else {
$message = sprintf( 'Email "%s"%s not sent: %s', $email_id, $object_label, $reason );
}
$context = array(
'source' => self::LOG_SOURCE,
'email_type' => $email_id,
'status' => $status,
'recipient' => $this->resolve_recipient( $email->get_recipient() ),
);
if ( null !== $reason ) {
$context['reason'] = $reason;
}
if ( ! empty( $object_context ) ) {
$context[ $object_context['type'] ] = $object_context['id'] ?? null;
}
/**
* Filter the context array logged for each transactional email attempt.
*
* This filter is documented in src/Internal/Email/EmailLogger.php
*
* @since 10.9.0
*/
$context = (array) apply_filters( 'woocommerce_email_log_context', $context, $email_id, $email );
wc_get_logger()->log( WC_Log_Levels::NOTICE, $message, $context );
}