How to subtract total_discount from line item price?

Highlighted
Tourist
5 0 0

I am trying to calculate the net total price of line items using the REST API after accounting for quantity and total_discount. It is not clear to me whether total_discount needs to be multiplied by quantity or not after reading the docs.


Which of these formulas would be correct?

 

Net line item price = (line_item.price - line_item.total_discount) * line_item.quantity

 

OR

 

Net line item price = (line_item.price * line_item.quantity) - line_item.total_discount

 

Any help would be much appreciated!

 

Thanks,

Jeff

0 Likes
Shopify Staff
Shopify Staff
1556 77 232

For each given line item, (line_item.price - line_item.total_discount) accurately represents the line item price after discounts. If this is a discount applying to all line items, then (line_item.price - line_item.total_discount) * line_item.quantity is applicable. I hope I'm understanding your issue correctly, you should be able to test this pretty easily unless I'm misunderstanding.

 

Cheers.

0 Likes