Search code examples
ruby-on-railsrubyruby-on-rails-4shopifyshopify-app

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.


Solution

  • 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!!