Add External Buy Button with Metafields to Product Page - Justin Hayward
- Open product.liquid and Locate {% if has_cart %}{% include 'product-add-to-cart-form' %}{% endif %}
- Replace the {% if has_cart %}{% include 'product-add-to-cart-form' %}{% endif %} with the following code
{% if product.metafields.external-url != blank %} <a href="{{ product.metafields.external-url.external-url }}" target="_blank" id="purchase" class="addtocart btn-main purchase-btn btn-primary"> PURCHASE </a><br /> {% else %} {% if has_cart %}{% include 'product-add-to-cart-form' %}{% endif %} {% endif %}
- Now anytime a product uses the metafields info and uses "external-url" for both the key and namespace, the external button will show instead of the standard add to cart button.
Reference: https://justin-hayward-2.myshopify.com/
