Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails

WCEmailTemplateChangeSummary::align_to_base │ public static │ WC 11.3.0

Match each base block to its counterpart in core and in the post. A core block and a post block are the same logical block only when both match the same base block. null means that side no longer has the block.

Public so WCEmailTemplateSelectiveApplier{} pairs blocks exactly the way the change summary shown to the merchant does.

Method of the class: WCEmailTemplateChangeSummary{}

No Hooks.

Returns

array<int, array{core:?int, post:?int}>. Keyed by base record index; values are core and post record indices.

Usage

$result = WCEmailTemplateChangeSummary::align_to_base( $core_records, $base_records, $post_records ): array;
$core_records(array) (required)
.
$base_records(array) (required)
.
$post_records(array) (required)
.

Changelog

Since 11.3.0 Introduced.

WCEmailTemplateChangeSummary::align_to_base() code WC 11.3.0

public static function align_to_base( array $core_records, array $base_records, array $post_records ): array {
	$base_to_core = array();
	foreach ( self::lcs_matches( $core_records, $base_records ) as $pair ) {
		$base_to_core[ $pair[1] ] = $pair[0];
	}
	$base_to_post = array();
	foreach ( self::lcs_matches( $post_records, $base_records ) as $pair ) {
		$base_to_post[ $pair[1] ] = $pair[0];
	}

	$alignment = array();
	foreach ( array_keys( $base_records ) as $b_idx ) {
		$alignment[ $b_idx ] = array(
			'core' => $base_to_core[ $b_idx ] ?? null,
			'post' => $base_to_post[ $b_idx ] ?? null,
		);
	}
	return $alignment;
}