I'm trying to add a 50% discount to all shipping classes in cart other than the highest shipping class.
If I have 3 products in the cart, each with its own shipping class pricing like P1=$150; P2=$200; P3=$300. Expected sum of shipping costs would be: (P1/50%)+(P2/50%)+P3(most expensive)= $475
Products with ID1, ID2, ID3 should not be discounted even if their shipping class is less expensive than others in the cart. Shipping for those products should always be fully charged.
First I tried to add a discount to a single shipping class using the shipping class slug, my question can be found here [question]: Shipping cost discount based on a shipping classes in Woocommerce
But I don't know how to retrieve the highest (most expensive) shipping class in a cart and discount all other shipping classes by 50%, because each time there may be a different shipping class (with different slug) in a cart that is most expensive.
I've been researching WooCommerce API documentation found here https://docs.woocommerce.com/wc-apidocs/class-WC_Shipping_Method.html but I can't tell which method would be helpful in my case.
It's a very similar request to this unanswered question Woocommerce shipping - multiple item discount with different prices per class
Is there a method to discount all shipping class prices on cart other than the most expensive one?