Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
How to apply discounts on line item level while creating an order using order create API? I have tried applying discounts on the specific line item with "total_discount","discount_allocations","total_discount_set" fields. But once the order is created the discount is getting applied on an order level.
Hey @sanjeev_kmr,
Those fields are read-only. You'll want to apply a discount which affects the line items.
Alternatively, you can apply line item discounts using checkout API or draft order API.
Scott | Developer 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
I just spent a LONG time trying to get it working.
The only way I could was to first created a Shopify Draft order, add an 'applied discount', then complete the draft order.
If you are using the shopify_api gem, it looks like this
order_params = {
line_items: [
{
variant_id: 39304862138471,
quantity: 1,
applied_discount: { value_type: 'fixed_amount', value: '100', amount: '100' }
}]
}
draft_shopify_order = ShopifyAPI::DraftOrder.new(order_params)
draft_shopify_order.save!
draft_shopify_order.complete({ payment_pending: true }) # because i dont want the status to be Paid
Hi. What are the writable fields?
User | RANK |
---|---|
6 | |
5 | |
5 | |
4 | |
4 |