Automattic\WooCommerce\Internal\OrderWithdrawal\Emails

OrderWithdrawalEmailPreview::prepare_email_for_preview │ public │ WC 11.2.0

Populate order withdrawal data for email previews.

Method of the class: OrderWithdrawalEmailPreview{}

No Hooks.

Returns

mixed.

Usage

$OrderWithdrawalEmailPreview = new OrderWithdrawalEmailPreview();
$OrderWithdrawalEmailPreview->prepare_email_for_preview( $email );
$email(mixed) (required)
Email being prepared for preview.

Changelog

Since 11.2.0 Introduced.

OrderWithdrawalEmailPreview::prepare_email_for_preview() code WC 11.2.1

public function prepare_email_for_preview( $email ) {
	if (
		(
			! $email instanceof WC_Email_Customer_Order_Withdrawal_Requested
			&& ! $email instanceof WC_Email_Order_Withdrawal_Requested
		)
		|| ! $email->object instanceof WC_Order
	) {
		return $email;
	}

	$order                                       = $email->object;
	$order_date                                  = $order->get_date_created();
	$email->withdrawal_data                      = array(
		OrderWithdrawalFormProcessor::FIELD_FIRST_NAME => $order->get_billing_first_name(),
		OrderWithdrawalFormProcessor::FIELD_LAST_NAME  => $order->get_billing_last_name(),
		OrderWithdrawalFormProcessor::FIELD_EMAIL      => $order->get_billing_email(),
		OrderWithdrawalFormProcessor::FIELD_ORDER_NUMBER => $order->get_order_number(),
		OrderWithdrawalFormProcessor::FIELD_WITHDRAWAL_TYPE => OrderWithdrawalFormProcessor::WITHDRAWAL_TYPE_SPECIFIC,
		OrderWithdrawalFormProcessor::FIELD_ADDITIONAL_DETAILS => __( 'I would like to withdraw the first item from this order.', 'woocommerce' ),
	);
	$email->submitted_at                         = $order_date ? $order_date->getTimestamp() : time();
	$email->placeholders['{order_number}']       = $order->get_order_number();
	$email->placeholders['{order_billing_name}'] = $order->get_formatted_billing_full_name();

	if ( $email instanceof WC_Email_Order_Withdrawal_Requested ) {
		$email->matched_order             = $order;
		$email->outside_withdrawal_window = false;
		$email->withdrawal_window_warning = '';
	}

	return $email;
}