Automattic\WooCommerce\Internal\Admin\EmailPreview

EmailPreview::set_email_type()publicWC 1.0

Set the email type to preview.

Method of the class: EmailPreview{}

Return

null. Nothing (null).

Usage

$EmailPreview = new EmailPreview();
$EmailPreview->set_email_type( $email_type );
$email_type(string) (required)
Email type.

EmailPreview::set_email_type() code WC 9.7.1

public function set_email_type( string $email_type ) {
	$emails = WC()->mailer()->get_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 );
		$this->email->user_email = '[email protected]';
		$this->email->user_login = 'user_preview';
		$this->email->set_object( $object );
	} else {
		$object = $this->get_dummy_order();
		if ( $email_type === 'WC_Email_Customer_Note' ) {
			$this->email->customer_note = $object->get_customer_note();
		}
		if ( $email_type === 'WC_Email_Customer_Refunded_Order' ) {
			$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 );
}