Automattic\WooCommerce\Internal\Admin\EmailPreview
EmailPreview::set_email_type
Set the email type to preview.
Method of the class: EmailPreview{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$EmailPreview = new EmailPreview(); $EmailPreview->set_email_type( $email_type );
- $email_type(string) (required)
- Email type.
EmailPreview::set_email_type() EmailPreview::set email type code WC 10.7.0
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 = '[email protected]';
$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 = __( "This is an order note sent from the Admin to the customer during fulfillment when you add a new Order Note and choose to send it to the customer.\n\nIt can be multiple lines.", 'woocommerce' );
}
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();
}