Automattic\WooCommerce\Internal\Email

EmailLogger::log_non_send_outcome │ private │ WC 1.0

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.

Метод класса: EmailLogger{}

Возвращает

void. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->log_non_send_outcome( $email_id, $email, $status, ?string $reason ): void;
$email_id(строка) (обязательный)
The email type ID.
$email(WC_Email) (обязательный)
The WC_Email instance.
$status(строка) (обязательный)
The outcome status: 'disabled' or 'skipped'.
?string $reason
.
По умолчанию: null

Код EmailLogger::log_non_send_outcome() WC 11.2.2

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 );
}