Join the Medusa Community
Join the Medusa Community on Discord to get help, share your knowledge, and stay up to date with the latest news and updates.
The problem
The problem is this: how can we increase the delivery price based on X or Y conditions? In the case of our community member, he wanted to increase the price based on a fixed amount, depending on the total number of items in the cart. For example:- Fixed amount of $5
- $2 per item added to the cart
The solution
What we need to keep in mind here is that we’ll need a new fulfillment provider, one that we can customize as we wish and inject our own logic. The official documentation covers the creation of a FulfillmentProvider very well “here” Once your FulfillmentProvider is created, the function we’re going to be interested in modifying iscalculatePrice
, it’s inside that the magic will happen
Don’t forget to enable your FulfillmentProvider in the Admin UI and setup everything related to it inside your regions.
calculated_amount
is the price that will be displayed to the customer and used for any further calculations inside Medusa.
Example in action
Below is a video showing you the complete process + an example on the Storefront.Conclusion
This is a simple example of how to implement dynamic shipping prices in Medusa and how to use thecalculatePrice
function.
You can find the complete code on “GitHub”
Join the Medusa Community
Join the Medusa Community on Discord to get help, share your knowledge, and stay up to date with the latest news and updates.