Automattic\WooCommerce\Internal\Email

EmailLogger::maybe_add_order_noteprivateWC 1.0

Add a private order note when a transactional email is sent or fails for an order.

Accepts mixed input because $email->object is loosely typed (any object the email subclass attaches), and we narrow to WC_Order at the top of the method before doing anything with it.

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

Хуки из метода

Возвращает

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

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

// private - только в коде основоного (родительского) класса
$result = $this->maybe_add_order_note( $wc_object, $email_id, $email, $success, ?string $error_reason ): void;
$wc_object(разное) (обязательный)
The email's related object, or false/null when none is set.
$email_id(строка) (обязательный)
The email type ID (e.g. customer_processing_order).
$email(WC_Email) (обязательный)
The WC_Email instance.
$success(true|false) (обязательный)
Whether the email was sent successfully.
?string $error_reason(обязательный)
.

Код EmailLogger::maybe_add_order_note() WC 11.0.1

private function maybe_add_order_note( $wc_object, string $email_id, WC_Email $email, bool $success, ?string $error_reason ): void {
	if ( ! $wc_object instanceof WC_Order || ! $wc_object->get_object_read() ) {
		return;
	}

	/**
	 * Filter whether to add an order note for this transactional email attempt.
	 *
	 * Return false to suppress the order note for a particular email or globally,
	 * while still allowing the WooCommerce logger entry to be written.
	 *
	 * @since 10.9.0
	 *
	 * @param bool     $enabled  Whether to add the order note.
	 * @param string   $email_id The email type ID.
	 * @param WC_Email $email    The WC_Email instance.
	 * @param WC_Order $order    The order the note would be added to.
	 */
	if ( ! apply_filters( 'woocommerce_email_log_add_order_note', true, $email_id, $email, $wc_object ) ) {
		return;
	}

	$email_title = $email->get_title();
	$email_label = '' !== $email_title ? $email_title : $email_id;

	if ( $success ) {
		$note = sprintf(
			/* translators: %s: Email title or type identifier */
			__( 'Email "%s" sent.', 'woocommerce' ),
			$email_label
		);
	} elseif ( $error_reason ) {
		$note = sprintf(
			/* translators: 1: Email title or type identifier, 2: Error reason */
			__( 'Email "%1$s" failed to send: %2$s.', 'woocommerce' ),
			$email_label,
			$this->redact_emails( $error_reason )
		);
	} else {
		$note = sprintf(
			/* translators: %s: Email title or type identifier */
			__( 'Email "%s" failed to send.', 'woocommerce' ),
			$email_label
		);
	}

	$wc_object->add_order_note( $note, 0, false, array( 'note_group' => OrderNoteGroup::EMAIL_NOTIFICATION ) );
}