Automattic\WooCommerce\Internal\Admin\Settings

Utils::order_map_place_at_order()public staticWC 1.0

Place an id at a specific order in an order map.

Метод класса: Utils{}

Хуков нет.

Возвращает

Массив. The updated order map.

Использование

$result = Utils::order_map_place_at_order( $order_map, $id, $order ): array;
$order_map(массив) (обязательный)
The order map.
$id(строка) (обязательный)
The id to place.
$order(int) (обязательный)
The order at which to place the id.

Код Utils::order_map_place_at_order() WC 9.6.1

public static function order_map_place_at_order( array $order_map, string $id, int $order ): array {
	// If the id is already at the desired order, return the order map as is.
	if ( isset( $order_map[ $id ] ) && $order_map[ $id ] === $order ) {
		return $order_map;
	}

	// If there is no id at the desired order, just place the id there.
	if ( ! in_array( $order, $order_map, true ) ) {
		$order_map[ $id ] = $order;

		return $order_map;
	}

	// Bump the order of everything with an order equal or higher than the desired order.
	foreach ( $order_map as $key => $value ) {
		if ( $value >= $order ) {
			++$order_map[ $key ];
		}
	}

	// Place the id at the desired order.
	$order_map[ $id ] = $order;

	return $order_map;
}