Edit buy-buttons.liquid to include conditional logic

Hello,

I am currently using the ‘Prestige’ theme and need to achieve the functionality where buy buttons are initially hidden ONLY on products listed in my ‘Add-Ons’ collection unless the customer has previously purchased an item from ‘The GR1’ collection.

I need to:

(1) ensure that a ‘Log in to continue’ message is displayed before my customer is logged in;

(2) verify that their purchase history shows at least 1 item from ‘The GR1’ collection, before the ‘Add to Cart’ option is made available.

This is my current buy-buttons.liquid code below:


{%- comment -%}

BUY BUTTONS

This component is used to show the buy buttons


Supported variables


  • product: the product from which to show the buttons (if empty, a placeholder is displayed)
  • show_payment_button: if we show or not the dynamic checkout button
  • show_gift_card_recipient: for gift card products, an optional message/email to be sent to the recipient
  • atc_button_background: the background of the ATC button
  • atc_button_text_color: the color of the ATC button
  • payment_button_background: the background of the dynamic payment button
  • payment_button_background: the color of the dynamic payment button
  • form_id: if specified, define the form ID linked to this input
    {%- endcomment -%}

{%- if product != blank -%}

{%- assign variant_picker_block = section.blocks | where: ‘type’, ‘variant_picker’ | first -%}

{%- assign recipient_feature_active = false -%}

{%- if product.gift_card? and show_gift_card_recipient -%}

{%- assign recipient_feature_active = true -%}
{%- assign show_payment_button = false -%}

{%- endif -%}

{%- form ‘product’, product, is: ‘product-form’, id: form_id -%}
<input type=“hidden” {% if variant_picker_block != blank %}disabled{% endif %} name=“id” value=“{{ product.selected_or_first_available_variant.id }}”>

{% liquid
assign button_disabled = false

if product.selected_or_first_available_variant.available == false

assign button_disabled = true
assign button_content = ‘product.general.sold_out_button’ | t

else

if product.template_suffix contains ‘pre-order’

assign button_content = ‘product.general.pre_order_button’ | t

else

assign button_content = ‘product.general.add_to_cart_button’ | t

endif

endif

%}

{%- if recipient_feature_active -%}

{%- assign checkbox_label = ‘gift_card.recipient.checkbox’ | t -%}
{%- render ‘checkbox’, label: checkbox_label, name: ‘properties[__shopify_send_gift_card_to_recipient]’ -%}

{%- liquid

assign recipient_email_label = ‘gift_card.recipient.email_label’ | t
render ‘input’, type: ‘email’, label: recipient_email_label, name: ‘properties[Recipient email]’, value: form.email, required: true

assign recipient_name_label = ‘gift_card.recipient.name_label’ | t
render ‘input’, label: recipient_name_label, name: ‘properties[Recipient name]’, value: form.name

assign send_on_label = ‘gift_card.recipient.send_on_label’ | t
render ‘input’, type: ‘date’, label: send_on_label, name: ‘properties[Send on]’, value: form.send_on, pattern: ‘\d{4}-\d{2}-\d{2}’
render ‘input’, type: ‘hidden’, name: ‘properties[__shopify_offset]’

assign message_label = ‘gift_card.recipient.message_label’ | t
render ‘input’, label: message_label, name: ‘properties[Message]’, value: form.message, multiline: 3, maxlength: 200, show_max_characters_count: true

-%}

{%- endif -%}

{%- if show_payment_button and atc_button_background == blank and atc_button_text_color == blank -%}

{%- assign atc_button_style = ‘outline’ -%}

{%- else -%}

{%- assign atc_button_style = ‘solid’ -%}

{%- endif -%}

{%- render ‘button’, content: button_content, type: ‘submit’, disabled: button_disabled, style: atc_button_style, background: atc_button_background, text_color: atc_button_text_color, stretch: true -%}

{%- if show_payment_button -%}

{{- form | payment_button -}}

#shopify-section-{{ section.id }} .shopify-payment-button { {%- if payment_button_background != blank and payment_button_background != 'rgba(0,0,0,0)' -%} --button-background: {{ payment_button_background.rgb }}; {%- endif -%} {%- if payment_button_text_color != blank and payment_button_text_color != 'rgba(0,0,0,0)' -%} --button-text-color: {{ payment_button_text_color.rgb }}; {%- endif -%} {%- unless product.selected_or_first_available_variant.available -%} display: none; {%- endunless -%} }

{%- endif -%}

{%- endform -%}

{%- else -%}

{%- assign button_content = ‘product.general.add_to_cart_button’ | t -%}
{%- render ‘button’, content: button_content, type: ‘submit’, background: variant_picker_block.settings.atc_button_background, text_color: variant_picker.settings.atc_button_text_color, stretch: true -%}

{%- endif -%}


I will greatly appreciate the help.
Thanks