How to add a core charge for battery purchases in cart?

I have a battery store in California that requires an automatic, refundable “core charge” on every battery purchased. Charge varies per battery type. I have this Liquid code from Chat GPT, but I’m not sure where to insert it. Any feedback is appreciated.

{% if item.product.type == ‘Battery’ %}
{% assign core_charge = 0 %}
{% case item.variant.title %}
{% when ‘Golf Cart’ %}
{% assign core_charge = 20.00 %}
{% when ‘Automotive’ %}
{% assign core_charge = 15.00 %}
{% when ‘Other Battery Type’ %}
{% assign core_charge = 10.00 %}
{% else %}
{% assign core_charge = 0 %}
{% endcase %}

{% if core_charge > 0 %}

Core Charge ({{ item.variant.title }}) ${{ core_charge | money }} {% endif %} {% endif %}

That’s liquid for customizing an online-sales channel theme, this is the subforum for the storefront HEADLESS APIS.

There’s tons of pre-existing posts on customizing themes to dynamically/automatically add products, “fees” , to a users cart findable by searching the forums.

Also since bunding is a native feature using a bundling app could do what’s needed.

There’s no where to insert it as that’s not how themes and products and changing prices work.

All that code would do is give you a variable with string to visually display an amount it doesn’t actually do anything substantial.

Don’t use glorified chatbot systems for this if you don’t have the experience to identify the garbage it’s serving it just gives misleading information leading to very bad expectations that waste time having to be corrected.

The theme system cannot generate products or generate “fees”, or modify prices, there has to be an actual existing “core charge” product added to the admin and published to the online sales channel.

Then it needs to be added to the cart on the frontend when the other product is added to the cart or pre-checkout.

If you need this process or theme customization created then contact me by email for services.
Contact info in forum signature.
ALWAYS please provide context, examples: store url, theme name, post url(s) , or any further detail in ALL correspondence.

Hi @team_mcrales ,

code mentioned above is good for display only this will not increase the cart value.

however you can custom dev this feature which will add a product named core charge with appropriate value.