Is it possible to offer free shipping only when a product discount or order discount created in the application is applied?
I would like to add a free shipping option to my product discounts and order discounts.
I tried this problem by rewriting shopify.extension.toml as follows but it did not solve the problem.
You can currently only have one target for discount functions. Your use case is not technically feasible with functions. One alternative is to automatically add a manual shipping code at checkout with an extension (our application Stackable now does this!).
Thanks for sharing my article; however, it is now outdated. Now that Shopify has released a new Discount Functions API, which allows multiple discount classes on the same Function instance, it should be possible to combine product/shipping discounts into the same code.
@tobebuilds I just encountered an issue with the new Discount Function API. It was working fine last week, but today when I tried to create a new one, it returned a product-discount instead.
When I checked the functions, I noticed that it only includes PRODUCT classes. I believe this issue started last Saturday or Sunday, because everything was still working correctly on Friday’s morning.
Shopify’s Discount Function API processes discounts in a specific order during cart evaluation:
Cart Lines Discounts (cart_lines_discounts_generate_run): This function applies discounts to individual cart lines (products) or the order subtotal. It outputs discount operations that Shopify applies to the cart.
Delivery Discounts (cart_delivery_options_discounts_generate_run): This function applies discounts to shipping options. It runs after cart line discounts are calculated and can access the cart’s state, including any applied discounts via the discountAllocations field.
The input to cart_delivery_options_discounts_generate_run includes the cart’s current state, which reflects discounts applied by cart_lines_discounts_generate_run. Specifically, the discountAllocations field in the cart or cart lines will contain details about discounts applied to products or the order subtotal.
using this you can decide on providing free shipping
using before query for cart_delivery_options_discounts_generate_run will provide data
query RunInput {
cart {
lines {
id
discountAllocations {
discountedAmount {
amount
}
}
}
cost {
subtotalAmount {
amount
}
discountAllocations {
discountedAmount {
amount
}
}
}
deliveryGroups {
id
deliveryOptions {
handle
cost {
amount
}
}
}
}
}