Covers all questions related to inventory management, order fulfillment, and shipping.
We have a Shopify app which is using CarrierService API to display shipping rates to the customers.
If a buyer applies a discount coupon at checkout page, we are not getting any information about the discount in the data received in callback url.
Is there any way to get the discounted cart total, and calculate and return shipping charges based on that to the checkout page?
Solved! Go to the solution
This is an accepted solution.
Hi Manujames,
Thanks for your post. The [CarrierService API] does not currently have a way to provide information about cart level discounts in the information sent to the callback url.
It's important to keep in mind that buyers can still add or remove discount codes on the payment step of checkout after the CarrierService API has acquired a rate on the shipping step so the total cart price could still change after that shipping price has been selected.
Hope you have a great day,
Jon551 | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hi there @manujames!
I just wanted to let you know I have moved your query here to our dedicated API forums.
As we're unable to provide this kind of support ourselves directly, this is the best place for this kind of question
These threads are monitored and responded to by our own developers and Partners, so there's a good chance you'll get some quality info here.
All the best
Don | Social Care @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
This is an accepted solution.
Hi Manujames,
Thanks for your post. The [CarrierService API] does not currently have a way to provide information about cart level discounts in the information sent to the callback url.
It's important to keep in mind that buyers can still add or remove discount codes on the payment step of checkout after the CarrierService API has acquired a rate on the shipping step so the total cart price could still change after that shipping price has been selected.
Hope you have a great day,
Jon551 | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hello Jon,
Thank you for the reply. I understood the scenario with discount codes being applied after the CarrierService API call.
However is it possible to provide discounted price in case of automatic discount in product level and order level?
Hi Manujames,
Thanks for your reply. Currently the information the CarrierService API sends to the callback url has a 'price' field for each line item, and that 'price' field shows the regular price (with no discounts at all) of a single instance of that line item without a decimal.
It wasn't mentioned in this thread but the 'grams' field also only shows the weight of a single instance of the line item.
So for example if the item's regular price is $1.00, each weighing 50 grams and the order contains 5 of them, the related data for that line item sent to the callback url would be like: "price"=>100, "quantity"=>5, "grams"=>50
Hope you have a great day,
Jon551 | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hi, we are sufferring with this issue too. How would you propose a store could (consistently) offer free shipping when the order total is over a certain amount? At the moment, if a discount applies that takes an order back below a threshold, the customer still (incorrectly) would get free shipping.
Sadly there is no solution to this.
I've faced this issue when I started developing Shopify Apps two and a half years ago, and at that time it was a known issue for years (Thread link for additional context: Discount info missing in shipping calculate webhook - Shopify Community)
I came here today to check if there was any updates regarding this, but things seems to be the same.
Once it is fully released, I'm hoping to use https://www.shopify.com/uk/enterprise/shopify-functions for our free shipping use case.
Adding or removing discount code in checkout's payment step still sends the information to the callback url and shipping rate in checkout is updated. It's just totally useless as the discount doesn't show up in the payload. I just can't understand the reasoning behind this. It would be very important to know what the customer is actually paying for the product when calculating the rate for shipping.
Hey,
Is this still the case? i want to change the 3rd party shipping method and i want to change the price based on the cart total,
there is any way to do it?
right now i calculate the items price, but it doesnt include discounts
thanks
We found a solution that worked for us since we are the developer of both our own CarrierService app and our store's theme. We noticed that `properties: {}` was being passed to our quote endpoint which gave us the idea to set private line item properties via the Ajax Cart API on the cart page for items adjusted via automatic discounts.
Any item in the cart that has a `discounted_price` lower than `price` gets a `_discounted_price` line item property set. This gets passed through to the quote and used in place of the price, if it exists on that item, otherwise it just falls back to the regular item price.
The only real downsides are:
// Example call to cart/change.js from cart page
jQuery.post(window.Shopify.routes.root + 'cart/change.js', {
line: item.index,
quantity: item.quantity,
properties: {
'_discounted_price': item.discounted_price
}
});
## Example calculation in our Ruby CarrierService quote method
cart_value = items.map{ |item| (item.dig(:properties, :_discounted_price) || item.price).to_i * (item[:quantity] || 0).to_i }.sum