Sometimes is useful order the cart items by price.
For example, I needed to sort items of the cart in a plugin that does discounts like ‘Buy 3 t-shirts get one free‘. If there are three t-shirts on the , the plugin applies the discount at the first t-short. Sorting by the price the plugin applies the discount to the shirt cheapest.
This function sorts an array such that array indices maintain their correlation with the array elements they are associated with, using a user-defined comparison function.
In the example I used the function wpm_sort_by_price, to sort the array $cart_sort in ascending order. To sort in descending order you should use the function ‘wpm_sort_by_price_desc’.