How can I export the shipping discount applied to the Shopify order?

The shipping discount applied to the order is stored in the discount_applications field, which is an array of discounts.

You can use this formula in the Calculated Fields section of EZ Exporter to export the shipping discount:

round_half_up(float(search_attributes({{ discount_applications }}, "shipping_line", search_key="target_type", result_key="value", default="0")) if search_attributes({{ discount_applications }}, "shipping_line", search_key="target_type", result_key="value_type") == "fixed_amount" else (float(search_attributes({{ discount_applications }}, "shipping_line", search_key="target_type", result_key="value", default="0")) / 100) * ({{ shipping_lines.total_price }} or 0), decimals=2)

This is quite complex as we have to parse the array first and filter it to retrieve the discount where the target_type is "shipping_line" (since this data can also include other types of discounts such as line item discounts).  The discount value may also be a fixed amount or a percentage, so we have to account for that as well using conditional logic.

Note that the above formula doesn't factor in order edits and refunds.  If you want to get the current shipping discount after order edits and refunds, you can use this formula below instead:

round_half_up(float(search_attributes({{ discount_applications }}, "shipping_line", search_key="target_type", result_key="value", default="0")) if search_attributes({{ discount_applications }}, "shipping_line", search_key="target_type", result_key="value_type") == "fixed_amount" else (float(search_attributes({{ discount_applications }}, "shipping_line", search_key="target_type", result_key="value", default="0")) / 100) * ({{ shipping_lines.current_total_price }} or 0), decimals=2)

Related Articles:


App: EZ Exporter

Tags: discounts, shipping