Post purchase extension shopify not apply shipping cost to order

Hi, I created a post purchase extension, and at the moment I have this problem, when I show the extension I always notice that after purchases the shipping cost is never applied for the purchased product, even though I applied it, can you help me?

setPurchaseOption((prevPurchaseOption) => ({
            ...prevPurchaseOption,
            changes: [
                {
                    ...prevPurchaseOption.changes[0],
                    variantID: parseInt(selectVariant.replace('gid://shopify/ProductVariant/', '')),
                    discount: {
                        ...prevPurchaseOption.changes[0].discount,
                        value: prevPurchaseOption.productDiscountType == '%' || prevPurchaseOption.productDiscountType == 'currency' ? parseFloat(prevPurchaseOption.productDiscount) : priceSelectVariant - parseFloat(prevPurchaseOption.productDiscount),
                    }
                },
                {
                    type: 'add_shipping_line',
                    price: offer.freeShipping ? 0 : parseFloat(offer.shippingCost)
                }
            ]
        }));

I apply the correct type to the changes object, and then send it to the sign-changeset API, as explained in the guide on shopify.dev

const signRes = await fetch(`${APP_URL}/api/sign-changeset`, {
                method: "POST",
                headers: {
                    Authorization: `Bearer ${inputData.token}`,
                    "Content-Type": "application/json",
                },
                body: JSON.stringify({
                    referenceId: inputData.initialPurchase.referenceId,
                    changes: purchaseOption,
                }),
            });

            const { token } = await signRes.json();

            // Make a request to Shopify servers to apply the changeset.
            let result = await applyChangeset(token);

Hi @cerz01

This is a common point of confusion when working with post-purchase extensions. The issue is not with your code, but with a specific limitation of the post-purchase extension framework itself.

According to Shopify’s design, post-purchase extensions are not permitted to add or modify shipping lines. The original shipping for the order has already been calculated and finalized in the main checkout step.

The Shopify API is likely silently ignoring the { type: 'add_shipping_line', ... } object within your changes array because it is not a supported change type in this context.

This is why you don’t see an error, but the shipping cost is also not applied. The post-purchase environment is strictly for adding products or applying discounts to the order, not for recalculating core costs like shipping or taxes.

The recommended and standard workaround for this is to incorporate the shipping cost directly into the price of the product you are offering.

You could create a specific product variant just for the post-purchase offer whose price is the sum of the item’s cost and the desired shipping fee.

This way, the customer pays a single price for the upsell item that already includes its shipping, and you can present this to the customer as “free shipping” on the offer.

Hope this helps!