Automattic\WooCommerce\Internal\Admin\EmailPreview

EmailPreview::set_email_typepublicWC 1.0

Set the email type to preview.

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

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

Возвращает

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

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

$EmailPreview = new EmailPreview();
$EmailPreview->set_email_type( $email_type );
$email_type(строка) (обязательный)
Email type.

Код EmailPreview::set_email_type() WC 10.3.4

public function set_email_type( string $email_type ) {
	$this->switch_to_site_locale();

	$wc_emails = WC()->mailer()->get_emails();
	$emails    = array_combine(
		array_map( 'get_class', $wc_emails ),
		$wc_emails
	);
	if ( ! in_array( $email_type, array_keys( $emails ), true ) ) {
		throw new \InvalidArgumentException( 'Invalid email type' );
	}
	$this->email_type = $email_type;
	$this->email      = $emails[ $email_type ];
	$object           = null;

	if ( in_array( $email_type, self::USER_OBJECT_EMAILS, true ) ) {
		$object                  = new WP_User( 0 );
		$object->user_email      = 'user_preview@example.com';
		$object->user_login      = 'user_preview';
		$object->first_name      = 'John';
		$object->last_name       = 'Doe';
		$this->email->user_email = $object->user_email;
		$this->email->user_login = $object->user_login;

		if ( property_exists( $this->email, 'reset_key' ) ) {
			$this->email->reset_key = 'reset_key';
		}

		if ( property_exists( $this->email, 'set_password_url' ) ) {
			$this->email->set_password_url = 'https://example.com/set-password';
		}

		if ( property_exists( $this->email, 'user_id' ) ) {
			$this->email->user_id = 0;
		}

		$this->email->set_object( $object );
	} else {
		$object = $this->get_dummy_order();
		if ( 'WC_Email_Customer_Note' === $email_type ) {
			$this->email->customer_note = $object->get_customer_note();
		}
		if ( 'WC_Email_Customer_Refunded_Order' === $email_type ) {
			$this->email->partial_refund = false;
		}
		$this->email->set_object( $object );
	}
	$this->email->placeholders = array_merge(
		$this->email->placeholders,
		$this->get_placeholders( $object )
	);

	/**
	 * Allow to modify the email object before rendering the preview to add additional data.
	 *
	 * @param WC_Email $email The email object.
	 *
	 * @since 9.6.0
	 */
	$this->email = apply_filters( 'woocommerce_prepare_email_for_preview', $this->email );

	$this->restore_locale();
}