Automattic\WooCommerce\Internal\Admin\Settings
Utils::order_map_place_at_order
Place an id at a specific order in an order map.
Method of the class: Utils{}
No Hooks.
Returns
Array. The updated order map.
Usage
$result = Utils::order_map_place_at_order( $order_map, $id, $order ): array;
- $order_map(array) (required)
- The order map.
- $id(string) (required)
- The id to place.
- $order(int) (required)
- The order at which to place the id.
Utils::order_map_place_at_order() Utils::order map place at order code WC 10.8.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;
}