Automattic\WooCommerce\Internal\StockNotifications\Emails

EmailManager::maybe_restore_customer_tax_location_datapublicWC 1.0

Restore customer tax location data from notification's metadata to display product prices in emails using the customer's tax location, if applicable.

Method of the class: EmailManager{}

No Hooks.

Returns

null. Nothing (null).

Usage

$EmailManager = new EmailManager();
$EmailManager->maybe_restore_customer_tax_location_data( $notification );
$notification(Notification) (required)
The notification object.

EmailManager::maybe_restore_customer_tax_location_data() code WC 10.3.6

public function maybe_restore_customer_tax_location_data( $notification ) {

	// No need if stores displaying price excluding tax.
	if ( 'incl' !== get_option( 'woocommerce_tax_display_shop' ) ) {
		return;
	}

	// Check if for some reason (e.g., 3PD), a WC_Customer is already assigned into the BG process's context.
	if ( ! empty( WC()->customer ) ) {
		return;
	}

	// Get the recorded customer data, if any.
	$location = $notification->get_meta( '_customer_location_data' );
	if ( empty( $location ) || ! is_array( $location ) || 4 !== count( $location ) ) {
		return;
	}

	// Restore the tax location.
	add_filter(
		'woocommerce_get_tax_location',
		function () use ( $location ) {
			return $location;
		}
	);
}