Personalized checkout and custom promotions with Shopify Scripts
Currently I have a script under Script Editor / Line Items / Bulk discounts.
The current documentation on scripts only allows for payment api and shipping api so I'm a little confused if this is even possible.
Is there away where I can pass data to the line item script using an asset file?
in example:
def tier_items(name)
myJsonData = {{ 'custom-scripts.js.liquid' | asset_url }}
return [
{
quantity: 1,
discount_type: :dollar,
discount_amount: 0.01,
discount_message: message_display(1, name),
},
The Ruby file kicks out an error since it's not liquid.
Solved! Go to the solution
This is an accepted solution.
Hey @Codesto1 , unfortunately you cannot use liquid code inside of a Shopify Script. Think of a Shopify Script as a special Ruby script which runs in a locked-down area and evaluates a restricted set of APIs before loading the steps of the checkout screen. Also, due to memory, computation, and timing restrictions, you cannot make network calls to load outside resources (like your json file).
You can however define some objects at the top of your Shopify Script and reference them later. You can see that in many of the examples that Shopify provides. But unfortunately those object definitions need to be fully contained in your script.
Lastly, some people find ways of doing fancy things using line item properties and/or metafields. But perhaps you could explain a bit more about exactly what scenario you are trying to solve for? It may help generate some more specific suggestions.
I hope that was helpful,
Matthew
This is an accepted solution.
Hey @Codesto1 , unfortunately you cannot use liquid code inside of a Shopify Script. Think of a Shopify Script as a special Ruby script which runs in a locked-down area and evaluates a restricted set of APIs before loading the steps of the checkout screen. Also, due to memory, computation, and timing restrictions, you cannot make network calls to load outside resources (like your json file).
You can however define some objects at the top of your Shopify Script and reference them later. You can see that in many of the examples that Shopify provides. But unfortunately those object definitions need to be fully contained in your script.
Lastly, some people find ways of doing fancy things using line item properties and/or metafields. But perhaps you could explain a bit more about exactly what scenario you are trying to solve for? It may help generate some more specific suggestions.
I hope that was helpful,
Matthew
Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025