Using Shopify Product Metafields in calculations

You have the ability to pass up to 5 Shopify product metafields to be used in calculations.

Before you will be able to get access to product metafields, you will need to create them in Shopify and configure them in Option Price Calculator Product App block.

How to Create Shopify Product Metafields #

https://help.shopify.com/en/manual/metafields

How to Configure Metafields in Option Price Calculator
#

JSON Templates #

Adding to Product Page Using Template Customizer

  1. Go to Online Store => Themes

  1. Click Customize on the theme you wan to add Option Price Calculator

  1. Open the product template you want to add Option Price Calculator

  1. Click the Option Price Calculator app block.

  1. Set up to 5 metafields. Click the dynamic source stack icon to select metafields configured on your product record.

    Although you can set any metafield, setting any field that does not contain a number or decimal will break your calculations if you use it

Manual Installed App #

1. Open the theme Code Editor.
Online Store -> Themes -> (Theme you want to install OPC) -> Actions -> Edit Code

2. Expand the “Snippets” folder in left navigation.

3. Click “opc-includes”.

4. Look for the following code (highlighted in red):

<div>
<product-options-section class=”app-block”>
<span
class=’product-id’
id='{{ product.id }}’
tags='{{ product.tags | json | escape }}’
variants='{{ product.variants | json | escape }}’
price='{{ product.selected_or_first_available_variant.price }}’
isavailable='{{ product.selected_or_first_available_variant.available }}’
metadata01='{{ block.settings.metadata01 }}’
metadata02='{{ block.settings.metadata02 }}’
metadata03='{{ block.settings.metadata03 }}’
metadata04='{{ block.settings.metadata04 }}’
metadata05='{{ block.settings.metadata05 }}’
style=”display: none”></span>
<div class=”optionTitle”></div>
<div class=”product-custom-option”></div>
<div class=”option-price-container”></div>
<div class=”add-to-cart-container”></div>
<div class=”product-error-msg”></div>
<div class=”custom-loading”></div>
<div class=”custom-cart-view”></div>
<div class=”custom-dimension-view”></div>
</product-options-section>
</div>

  1. Replace {{ block.settings.metadata01 }} with the reference to a product metafield element you want to use in a calculation.

    Example: {{ product.metafields.custom.box_price }}

    You can get the reference to the metafield element from:
    Shopify Settings => Metafields => Products
  1. Save the opc-includes file.

Add metafields into your calculations. #

From an Option Set Calculation or formula field, select a product metadata calculation variable.