Shipping script customization ( Discount shipping rate if it's more than 75 )

Topic summary

Goal: Enforce a flat shipping charge of 75 even when an order ships from multiple locations. Currently, customers are charged 75 per location (e.g., 3 locations → 225), but the merchant wants a single 75 total.

Context: The store has three locations, each with a shipping rate of 75. The merchant wants to avoid cumulative charges when items come from different locations in the same order.

Attempted solution: A Shopify Shipping Script was shared that iterates through input.shipping_rates, filters for source == “shopify”, and caps shipping_rate.price at 75 before assigning output.shipping_rates. Despite this, the total still reflects multiple 75 charges.

Status: The provided script did not achieve the desired flat-rate outcome. Guidance is requested on how to correctly adjust or redesign the script/logic to prevent stacking rates across locations and charge only a single 75. No resolution yet.

Summarized with AI on January 25. AI used: gpt-5.

I need help editing this script
If shipping_rate.price is greater than 75 make it 75
because we have 3 different locations that have 3 different shipping rate = 75
but we are in a small country and we want to make our shipping rate flat 75 no matter if customer picked items from different locations

but what is happening now that if the customer picked items from 3 location

he will pay 75+75+75
We want him to pay only 75

I tried to use this code

input.shipping_rates.each do |shipping_rate|
  next unless shipping_rate.source == "shopify"
  
  if shipping_rate.price > 75
    shipping_rate.price = 75
  end
  
 

output.shipping_rates = input.shipping_rates

but it didn’t work