Ad

Add One Button In Shopify Site Header Using Shopify App In ROR

I need to insert one button after search icon in shopify sites throgh the shopify app.Give me some suggestions.

Like this image

Thanks in Advance.

Ad

Answer

Hopefully you should replace/overwrite your snippets/header.liquid file in your store's theme with the help of Shopify API as below:

In your app, try the below in your root function as:

header = ShopifyAPI::Asset.find("sections/header.liquid")
header.value # returns the contents of the header.liquid

update your header.value using rails sub! as:

#this will add the button at appropriate place instead `{% endif %}`
header.value.sub!("{% endif %}", "<button type='button'>Click Button</button> {% endif %}") 

#do save    
header.save

Hope this will help you!!

Ad
source: stackoverflow.com
Ad