Automattic\WooCommerce\Internal\Admin\Settings
PaymentsProviders::payment_providers_order_map_apply_mappings
Apply order mappings to a base payment providers order map.
Method of the class: PaymentsProviders{}
No Hooks.
Returns
Array. The updated base order map, normalized.
Usage
// private - for code of main (parent) class only $result = $this->payment_providers_order_map_apply_mappings( $base_map, $new_mappings ): array;
- $base_map(array) (required)
- The base order map.
- $new_mappings(array) (required)
- The order mappings to apply. This can be a full or partial list of the base one, but it can also contain (only) new provider IDs and their orders.
PaymentsProviders::payment_providers_order_map_apply_mappings() PaymentsProviders::payment providers order map apply mappings code WC 10.7.0
private function payment_providers_order_map_apply_mappings( array $base_map, array $new_mappings ): array {
// Sanity checks.
// Remove any null or non-integer values.
$new_mappings = array_filter( $new_mappings, 'is_int' );
if ( empty( $new_mappings ) ) {
$new_mappings = array();
}
// If we have no existing order map or
// both the base and the new map have the same length and keys, we can simply use the new map.
if ( empty( $base_map ) ||
( count( $base_map ) === count( $new_mappings ) &&
empty( array_diff( array_keys( $base_map ), array_keys( $new_mappings ) ) ) )
) {
$new_order_map = $new_mappings;
} else {
// If we are dealing with ONLY offline PMs updates (for all that are registered) and their group is present,
// normalize the new order map to keep behavior as intended (i.e., reorder only inside the offline PMs list).
$offline_pms = $this->get_offline_payment_methods_gateways();
// Make it a list keyed by the payment gateway ID.
$offline_pms = array_combine(
array_map(
fn( $gateway ) => $gateway->id,
$offline_pms
),
$offline_pms
);
if (
isset( $base_map[ self::OFFLINE_METHODS_ORDERING_GROUP ] ) &&
count( $new_mappings ) === count( $offline_pms ) &&
empty( array_diff( array_keys( $new_mappings ), array_keys( $offline_pms ) ) )
) {
$new_mappings = Utils::order_map_change_min_order( $new_mappings, $base_map[ self::OFFLINE_METHODS_ORDERING_GROUP ] + 1 );
}
$new_order_map = Utils::order_map_apply_mappings( $base_map, $new_mappings );
}
return Utils::order_map_normalize( $new_order_map );
}