How can I add custom line items to the cart from the store's front end?

Using either the Order Editing API or Draft Orders, you can add a custom line item to the cart:(https://shopify.dev/tutorials/edit-an-existing-order-with-admin-api#add-a-custom-line-item).

Custom line items are items that can be charged for, but are not tied to an actual product (i.e. they don’t have a variant/product ID).

Is there any way to add such items to the cart from the front end of the store?

Hello, @Chris_Marshall1 .

Elias here with Shopify Support. Thank you for reaching out.

I understand you’re looking to add custom line items, which aren’t associated with your products, but can be charged for on the storefront. While you can add custom fields to capture information from your customers, it’s not possible to add a fee to this without creating them as a form of product or variant.

Some merchants have been able to add a gift-wrap option to their cart and change the wording for gift-wrap to their add-on. That said, I don’t have enough information about your add-on to determine if this is a workable solution for your store.

Alternatively, you can use a third-party app that has the function to create options for your products and add costs, this doesn’t require creating a variant and the options can be different for each product. I’ve handpicked a couple of apps that can create options and associate a cost for those options for you to try:

If you need any assistance with these apps, you can always reach out to the developers directly through the contact information found in the Support section of the app’s page.

Let me know if this is what you’re looking for? If you have any other questions on options, don’t hesitate to let me know in this thread!

2 Likes

As a workaround, could you make a call to create a variant in realtime (using Admin API), then add it to the cart? Then after checkout, could you delete that variant?

1 Like

Yes - and we’ve done this on a project recently :smiley:

1 Like

Hey @Chris_Marshall1 I have been investigating this for the last few days looking for a custom work around but it seems a non-product fee cannot be done still.

If you are using carrier calculated shipping rates, you can add a handling fee to them that shows up as a non-variant add on to the checkout UI by the tax field. I am not using carrier calc rates unfortunately so this is out of the question for me…

Check it out:
https://community.shopify.com/c/shopify-discussions/how-to-add-a-handling-fee/m-p/490575#M120146
But it doesnt specify which shipping rates so see below screenshot
https://www.screencast.com/t/2aDK5RxqBwR

Good luck!

How did you add the variant to the cart? Do you need to use Storefront API or can you use the Checkout in the Admin API?

How did you add the variant to the cart? Do you need to use Storefront API or can you use the Checkout in the Admin API?

I’m trying to modify a checkout before it’s completed (ie. in the checkouts/create webhook, I want to add a Variant to the lineItems). When a checkout is created, I want to add a specific Product Variant to the line Items of the checkout. Is there a way to do this? I’ve tried the checkout PUT endpoint but getting a 404

It is actually possible relatively elegant with a Shopify function and a line item property. You can use the cart transform ( Cart Transform Function API ) to expend the product into a bundle of the original product and an additional variant. The advantage is you can change the price for the variant.