1
votes

I am trying to write a Shopify application and I want to add a section to the product page when the store owner installed my app. I tried this by adding a custom script tag in the shop template and this tag will load and inject my desired HTML into the page. It's work but it needs to force the store owner to change the product page template and its not user-friendly.

I see some apps in the Shopify app store that can change the product page after you install them without needs add any part to the product page template. How they do this work? I can't find the correct way in the Shopify documents.

1
Making automatic modifications to theme files is a bad idea. Better make a good tutorial how can the clients modify their files on their own or provide free install feed instead. If the client deicides to remove your app he will be left with the modified code by your app which in most cases is not a good idea.drip

1 Answers

1
votes

You can change the Shopify theme of the shop using The API for Assets:

However as drip mentioned this is not a good idea:

  • If you change the theme auto-magically via code, you are looking for trouble. A lot of things can go wrong - simply you cannot cater for all themes and their changes over time! So you could possibly leave a broken page after the change. The e-shop owner won't be impressed! Actually a lot of the 1* reviews of apps are for that reason!
  • What would happen if the eshop owner removes your app? He won't know what code to remove.

So, most apps ask the user to add the app code. They provide detailed instructions of course.

Fyi, another problematic approach is the following:

Some apps may attempt to change the DOM "on the fly", by first locating an existing DOM element (a lot of theme-specific if statements to do that with any degree of success) and, then insert the app's DOM elements. That's very messy and problematic as well, but at least you do not risk ruining the owner's theme files. In the worst case he can uninstall your app and he 'll be ok.