In an app’s Discount Function, can the Function see other discounts applied on the checkout from other sources? The case we are trying to do here is make a “free shipping” discount function on our app’s carrier service rates, based on the value of the order total after any other discounts. Is this possible? We cannot add UI extensions because not all merchants’ stores are Plus and I don’t know if we can push a discount allocator function in production at this moment.
Discount Functions cannot view other discounts applied during checkout. However, they can observe their effects. In this case, you can check the subtotalAmount in your discount Function, which reflects the subtotal after any order and product discounts have been applied. Note this will be true only for shipping discounts, as they apply after order and product discounts.
Yes the case here is for a Discount Function that will apply a shipping discount. Basically, imagine an app that uses the Carrier Services API to generate dynamic rates for a merchant’s checkout. Also, picture that the merchant is allowed to set shipping costs as well as “free shipping” for these rates through the app, where the rule is “if the order total exceeds this X amount, then apply free shipping costs”.
Calculating the cost of rates that will be sent as a response in the app’s carrier service callback handler is limited, because the callback handler receives only the cart line items in the request, with their original prices and quantities. Therefore, the handler cannot at this point view any discounts applied on the checkout.
If however, the handler does not handle the calculation of free shipping, and instead we create a Discount Function in the app that decides whether to give the app’s carrier service rates free shipping or not, based on the order subtotal (after order and product discounts have been applied), then we may have solved our issue!