How to put the price in the add to cart button?

Hey i am currently building my store and the price is adding up to much space so i would like it to be in the add to cart button, but dont know how to. Does anybody know how to do this with code?

Example: ADD TO CART €19

link:https://e8aaa0-3.myshopify.com/

password:mohwhi

kind regards

Daan

Hi @PRETTYFRIDAYS ,

I can help you make the required changes on the ATC button. As we will have to update the template to add price, can you provide theme edit access to me?

sorry i can make the price show, can you give me a code?

Kind regards

Daan

As your theme is not a free theme, I cannot write code without looking into the actual template file. So can you provide me a copy of main-product.liquid and buy-buttons.liquid instead?

{% comment %}
  Renders product buy-buttons.
  Accepts:
  - product: {Object} product object.
  - block: {Object} passing the block information.
  - product_form_id: {String} product form id.
  - section_id: {String} id of section to which this snippet belongs.
  - show_pickup_availability: {Boolean} for the pickup availability. If true the pickup availability is rendered, false - not rendered (optional).

  Usage:
  {% render 'buy-buttons', block: block, product: product, product_form_id: product_form_id, section_id: section.id, show_pickup_availability: true %}
{% endcomment %}

  {%- if product != blank -%}
    {%- liquid
      assign gift_card_recipient_feature_active = false
      if block.settings.show_gift_card_recipient and product.gift_card?
        assign gift_card_recipient_feature_active = true
      endif

      assign show_dynamic_checkout = false
      if block.settings.show_dynamic_checkout and gift_card_recipient_feature_active == false
        assign show_dynamic_checkout = true
      endif
    -%}

    
  {%- else -%}
    

      

        
      

    

  {%- endif -%}

  {%- if show_pickup_availability -%}
    {{ 'component-pickup-availability.css' | asset_url | stylesheet_tag }}

    {%- assign pick_up_availabilities = product.selected_or_first_available_variant.store_availabilities
      | where: 'pick_up_enabled', true
    -%}

    

    
  {%- endif -%}

@PRETTYFRIDAYS

Please try replacing the above code with below codes.

Note: Please take backup of original code before making any changes on the theme level.

{% comment %}
  Renders product buy-buttons.
  Accepts:
  - product: {Object} product object.
  - block: {Object} passing the block information.
  - product_form_id: {String} product form id.
  - section_id: {String} id of section to which this snippet belongs.
  - show_pickup_availability: {Boolean} for the pickup availability. If true the pickup availability is rendered, false - not rendered (optional).

  Usage:
  {% render 'buy-buttons', block: block, product: product, product_form_id: product_form_id, section_id: section.id, show_pickup_availability: true %}
{% endcomment %}

  {%- if product != blank -%}
    {%- liquid
      assign gift_card_recipient_feature_active = false
      if block.settings.show_gift_card_recipient and product.gift_card?
        assign gift_card_recipient_feature_active = true
      endif

      assign show_dynamic_checkout = false
      if block.settings.show_dynamic_checkout and gift_card_recipient_feature_active == false
        assign show_dynamic_checkout = true
      endif
    -%}

    
  {%- else -%}
    

      

        
      

    

  {%- endif -%}

  {%- if show_pickup_availability -%}
    {{ 'component-pickup-availability.css' | asset_url | stylesheet_tag }}

    {%- assign pick_up_availabilities = product.selected_or_first_available_variant.store_availabilities
      | where: 'pick_up_enabled', true
    -%}

    

    
  {%- endif -%}

Hey thank you very much it worked!!! but i have one problem, can i maybe add more margin between the add to cart and price?

Much appreciated

Daan

Hi @PRETTYFRIDAYS ,

Please replace the original code with this updated code. I have added a little margin between price and text

{% comment %}
  Renders product buy-buttons.
  Accepts:
  - product: {Object} product object.
  - block: {Object} passing the block information.
  - product_form_id: {String} product form id.
  - section_id: {String} id of section to which this snippet belongs.
  - show_pickup_availability: {Boolean} for the pickup availability. If true the pickup availability is rendered, false - not rendered (optional).

  Usage:
  {% render 'buy-buttons', block: block, product: product, product_form_id: product_form_id, section_id: section.id, show_pickup_availability: true %}
{% endcomment %}

  {%- if product != blank -%}
    {%- liquid
      assign gift_card_recipient_feature_active = false
      if block.settings.show_gift_card_recipient and product.gift_card?
        assign gift_card_recipient_feature_active = true
      endif

      assign show_dynamic_checkout = false
      if block.settings.show_dynamic_checkout and gift_card_recipient_feature_active == false
        assign show_dynamic_checkout = true
      endif
    -%}

    
  {%- else -%}
    

      

        
      

    

  {%- endif -%}

  {%- if show_pickup_availability -%}
    {{ 'component-pickup-availability.css' | asset_url | stylesheet_tag }}

    {%- assign pick_up_availabilities = product.selected_or_first_available_variant.store_availabilities
      | where: 'pick_up_enabled', true
    -%}

    

    
  {%- endif -%}

Hey, thanks for your help btw, but can you also do this for the collection page?

Kind regards

Daan

Hi

I can add prices to the collection pages, but this will require changes to the theme files. It will take some time to implement, as I need to work on your specific theme.

Hi. Thanks for sharing your knowledge. I’m using the Dawn theme and the code works for single priced products but not for products with variables. I’ve been trying to tweak the code but somehow I can’t make it work. Any chance you could point me in the right direction?

Thanks fo much!

hello! Did you get the solution?

Sorry no I haven’t been able to figure it out. It turned out to be more complex than I thought.