New Line Item w Variant for "processing fee"

I’m developing a Line Item Script to apply ticketing fees (for livestream products) to the cart. Here’s how I’m attempting to do this:

  1. Check to see if cart has “Livestream” type product(s)

  2. Check cart for existing “Fee” type product

  3. if 1=true and 2=true, drop fee product, create new variant and add new line item

  4. if 1=true and 2=false, create new variant and add new line item

I’ve not found where to add a line item with dynamic product variant yet using Shopify+ Script Editor. Any links or help would be awesome. As well, it seems that the product information isn’t ready available from the line_item like it is within liquid object structures, so info on that may be helpful as well.

I am continuing to dig and learn about the functionality here, but I need to move fast.

Further, if someone wants to jump on with me, I can gladly pay you to help me get over this hurdle.

Thanks!

Update, I’ve figured out how to dig out the product_type from line_item.variant.product.product_type

So, that is fine. But, creating a new LineItem of product “x” or removing a line item is now the issue.

Ok, so, after some R&D, it looks like Script Editor is not the way to handle this…

Likely, I need to do all of this with Javascript…

Looking into possibly using the Shipping fees