Help Making App That Adds JS Code To Theme Files

EphraimMulilo
Tourist
20 0 3

Hello,

 I have written some JavaScript code that redirects new users to the checkout page after they've created an account. I'm currently using this piece of code in all 5 Shopify stores I own. I would like to create an app that simply pastes the JavaScript code in the index.liquid, login.liquid and accounts.liquid files of whatever store it's installed in.

I'm not that much of a programmer but I'm pretty good at finding pieces of code online and meshing them together to get them to do what I want. I've already set up a basic Shopify App that displays information and I've installed it on a development store using this guide https://shopify.dev/tutorials/build-a-shopify-app-with-node-and-react

Now what I would like to do is have the app automatically paste the JavaScript code in the index.liquid, login.liquid & accounts.liquid when it's installed to a store. Any help on how I can do this?

0 Likes
BStubbs
Shopify Partner
127 14 51

Hey @EphraimMulilo 

best way to start is to look at the docs on shopify.dev

The docs are pretty extensive. But basically what you want to do is when the app installs, access each one of those specific files using the Admin API and the Themes endpoint. https://shopify.dev/docs/admin-api/rest/reference/online-store/asset

Each of the liquid files are Assets. So just look up each one and make the changes to the value. Pretty easy!

Was this helpful? Press like!
Did it fix the problem? Mark it as the solution for others!
Buy me a beer? Well, sure!
0 Likes