How can I calculate the shipping price after the shipping discount?

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 calculate the total shipping price charged to the customer minus the shipping discount:

round_half_up(({{ shipping_lines.total_price }} or 0) - (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.


App: EZ Exporter

Tags: advanced features, shipping, order export, calculated fields