Editing order line items

We process subscription orders using Recharge. Every month, we want to send customers a free sample with their order. So that our warehouse team know what to pack and when, we want to run a background job that will loop through subscription orders as they come in, and modify them to include the free sample item.

When doing so, the sample item should not be charged to the customer, and ideally we would like to add a custom attribute to the line item for record-keeping (.e.g _free_sample).

I had a look at the documentation here, and have a few questions:

  1. I think we need to use the orderEditAddVariant mutation. If we use this, can I just confirm that the customer will not be charged? I ask as it doesn’t look like we can override the amount (in the event the free sample might be sold on our site as an actual product). If the customer is charged, is the solution to apply a discount using orderEditAddLineItemDiscount?
  2. Alternatively, we could use orderEditAddCustomItem – where it looks like we can set a price of 0. However, it doesn’t look like we can link this to a product / variant, which has implications for inventory management among other things.
  3. It doesn’t look like either of these methods allows for custom attributes to be set. Is this indeed the case, and if so, is there any workaround? I guess we could cancel and recreate the order with the new line items, but this seems fairly cumbersome.

Any advice would be greatly appreciated, thank you in advance.

1 Like

Hey @sebastienpowell, since you are already using Recharge, it looks like they have already developed a feature for this. this would be the easiest way I think: https://support.getrecharge.com/hc/en-us/articles/27248632651671-Understanding-the-Incentive-node-when-building-Subscription-Experiences

If that isn’t going to work, using the orderEdit to add the variant and then add a discount to the variant would be the best to ensure inventory is tracked properly.

For the line item attributes, that can’t be added in an order edit, but you could use the orderUpdate mutation to add order level attributes, tags or metafields.

Great, thank you @KyleG-Shopify! Interesting RE: Recharge – I hadn’t come across this feature. I think we’ll still implement our own, as there’s additional logic involved – e.g. randomise products according to specific logic, dispatch only if in stock etc – which it doesn’t look like the feature supports.

I’ll try the approach you suggested. Thank you!

1 Like