Automattic\WooCommerce\Internal\EmailEditor

Integration::update_send_preview_email_personalizer_contextpublicWC 1.0

Update the personalizer context for the send preview email.

Method of the class: Integration{}

No Hooks.

Returns

array. The updated personalizer context.

Usage

$Integration = new Integration();
$Integration->update_send_preview_email_personalizer_context( $context );
$context(array) (required)
The personalizer context.

Integration::update_send_preview_email_personalizer_context() code WC 11.1.2

public function update_send_preview_email_personalizer_context( $context ) {
	$post_manager = WCTransactionalEmailPostsManager::get_instance();
	$email_id     = $post_manager->get_email_type_from_post_id( get_the_ID() );
	if ( ! $email_id && '' !== $this->sending_preview_for_email_type ) {
		// Postless send-preview: there is no post to resolve the email
		// from, the type comes from the request instead.
		$email_id = $this->sending_preview_for_email_type;
	}
	$email_type    = $email_id ? $post_manager->get_email_type_class_name_from_email_id( $email_id ) : EmailPreview::DEFAULT_EMAIL_TYPE;
	$email_preview = wc_get_container()->get( EmailPreview::class );

	try {
		$email_preview->set_email_type( $email_type );
	} catch ( \InvalidArgumentException $e ) {
		// If the email type is invalid, return the context data as is.
		return $context;
	}

	$email            = $email_preview->get_email();
	$email->recipient = $context['recipient_email'] ?? '';
	$personalizer     = wc_get_container()->get( TransactionalEmailPersonalizer::class );

	return $personalizer->prepare_context_data( $context, $email );
}