FROM CACHE - en_header

Return management just got easier! We’ve launched Customer Self-Serve Returns to all Shopify merchants. Click here to learn more about how to activate this in your store.

Online store - Add dynamic checkout buttons to products

Community Manager
Community Manager
417 40 1135

You can update the product form on the product page template to support dynamic checkout buttons. If your theme has a home page featured product section, then you can update the product form in that template as well.


You can learn more about dynamic checkout buttons in Adding dynamic checkout buttons to your online store.



To update the product form to support dynamic checkout buttons



  1. From your Shopify admin, go to Online Store > Themes.
  2. Find the theme you want to edit, and then click Actions > Edit code.
  3. In the Sections directory, open one of the following files:

    • Click product-template.liquid to update the product page template. In some themes, the product template has a different filename. In some cases, the product form is included in a file in the Snippets directory, and has a name like product-form.liquid.
    • Click featured-product.liquid to update the home page featured product section.

  4. Find the product form by searching for <form action="/cart/add". Take note of any attributes that the form has, such as a class or an id. You can include these attributes in the updated product form that you will create in the next step. If you don't include the attributes, then the styling or behavior of the form might be affected.
  5. Delete the entire opening <form> tag, and replace it with the following Liquid:

    {% form 'product', product %}


    To include the attributes from the old form, add them to your updated form by using the following syntax:

    {% form 'product', product, id: "oldID", class: "old-class" %}


    To learn more about modifying form attributes, see the Liquid reference for form tags.

  6. Find the closing </form> tag by searching for </form>.
  7. Replace the closing </form> tag with the following Liquid:

    {% endform %}


  8. Find the Add to cart button by searching for an input or a button tag that has the attribute type="submit".
  9. On a new line below the Add to cart button, add the following Liquid:

    {{ form | payment_button }}


  10. Click Save.

    Your modified product form should look something like this example code:

    {% form 'product', product %}
      <button type="submit">Add to cart</button>
      {{ form | payment_button }}
    {% endform %}


TyW | Online Community Manager @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

Replies 7 (7)
3 1 1
Shopify Partner
8 0 2

Super helpful! you can add custom attributes as well!

{% form "product", product, id: "newID", class: "custom-class", data-example: "100" %}
Shopify Partner
2 0 3

Hi Bryan,

Is it possible to change the function of buy now button to (add to cart then redirect to checkout) ?

New Member
1 0 1

Is there a way to add one more button like 'Buy Now', to perform some custom action??

New Member
2 0 0

did you able to perform a custom action with this button?

New Member
2 0 0

Did you manage to do that? I wanna change the function of buy now button to redirect to a transparent checkout from another company 

New Member
1 0 0

Hi, it works in its simplest form but can you identify how to (a) Adjust the formatting on mobile - the text alignment is slightly out and b) make it responsive to products with options - at the moment, clicking the 'buy now' button just checks out with the first option listed, not the option selected. It also seems to have interfered with the 'add to cart' button. Same again, you cannot select the option.


Any help/guidance very much appreciated. TIA.