Hi,
This is what I want to achieve:
- If a discount name exists at checkout I want to reorder my shipping methods by name
- Automatically select the first shipping method available
The problem I’m finding:
- Reordering the shipping options is working when a user enters a specific discount name
- However the selected options is not the first shipping method available, it keeps the previously selected shipping method
This is my code:
discount_applies = Input.cart.discount_code && Input.cart.discount_code.code == "FREEDOM"
# Create array of shipping methods
desired_order = ["Next Working Day"]
if discount_applies
# Reorder the payment gateway methods to the order of desired_order.
Output.shipping_rates = Input.shipping_rates.sort_by do |shipping_rate|
desired_order.index(shipping_rate.name) || desired_order.length
end
else
Output.shipping_rates = Input.shipping_rates
end
See attached image to see the results when adding the discount code
Thanks,
N
