Home
Theme & Metafields

Product Variant Level Metafields

Key: sellingplanids Type: json Namespace: restockrocketproduction Owner: Product Variant

1. Selling Plan IDs Metafield

Configuration

  • Key: selling_plan_ids
  • Type: json
  • Namespace: restockrocket_production
  • Owner: Product Variant

Purpose

  • Stores the list of selling plan IDs associated with a variant
  • Used to track which preorder plans are available for a variant
  • Enables quick lookup of available preorder options
  • Stored as a JSON array of selling plan IDs

Accessing in Liquid


{% assign selling_plan_ids = product_variant.metafields.restockrocket_production.selling_plan_ids.value | json %}

2. Preorder Count Metafield

Configuration

  • Key: preorder_count
  • Type: number_integer
  • Namespace: restockrocket_production
  • Owner: Product Variant

Purpose

  • Tracks the current number of preorders for a specific variant
  • Used for inventory management and display
  • Automatically updated when orders are processed

Accessing in Liquid

{% assign preorder_count = product_variant.metafields.restockrocket_production.preorder_count %}

3. Preorder Max Count Metafield

Configuration

  • Key: preorder_max_count
  • Type: number_integer
  • Namespace: restockrocket_production
  • Owner: Product Variant

Purpose

  • Sets the maximum number of preorders allowed for a variant
  • Controls inventory policy switching
  • Triggers blocking orders when count reaches max

Accessing in Liquid

{% assign preorder_max_count = product_variant.metafields.restockrocket_production.preorder_max_count %}

Example Usage: Preorder Count and Max count

{% assign variant = product.selected_or_first_available_variant %}
{% assign preorder_count = variant.metafields.restockrocket_production.preorder_count.value | default: 0 %}
{% assign preorder_max = variant.metafields.restockrocket_production.preorder_max_count.value %}

{% if preorder_max %}
  {% assign spots_remaining = preorder_max | minus: preorder_count %}

  {% if spots_remaining > 0 %}
    <div class="preorder-availability">
      <span class="spots-left">{{ spots_remaining }} spots remaining</span>
      {% if spots_remaining < 5 %}
        <span class="low-stock-warning">Almost sold out!</span>
      {% endif %}
    </div>
  {% else %}
    <div class="preorder-full">
      Preorder limit reached
    </div>
  {% endif %}
{% endif %}
# Query to get metafields for a specific product variant
{
  productVariant(id: "gid://shopify/ProductVariant/YOUR_VARIANT_ID") {
    metafields(
      namespace: "restockrocket_production",
      first: 10
    ) {
      edges {
        node {
          id
          namespace
          key
          value
          type
        }
      }
    }
  }
}

# Query to get specific metafields for multiple variants of a product
{
  product(id: "gid://shopify/Product/YOUR_PRODUCT_ID") {
    variants(first: 10) {
      edges {
        node {
          id
          title
          metafields(
            namespace: "restockrocket_production",
            keys: ["preorder_count", "preorder_max_count", "shipping_text"]
          ) {
            edges {
              node {
                id
                key
                value
                type
              }
            }
          }
        }
      }
    }
  }
}

4. Shipping Text Metafield

Configuration

  • Key: shipping_text
  • Type: single_line_text_field
  • Namespace: restockrocket_production
  • Owner: Product Variant
Note

Most stores will not have this metafield.

The variant-level shipping_text metafield is only written when a merchant sets a per-variant shipping-text override for that variant in the offer's Variants tab — and it's only used at runtime when the offer's "Apply shipping text to all products" setting is off (shipping_applies_to_all_products = false).

For the typical store — one shipping message for the whole offer (shipping_applies_to_all_products = true, the default) — STOQ stores the shipping text once on the offer, not on each variant, so this variant metafield will not exist and the Liquid below returns nothing.

To read an offer's shipping text reliably, use the shop-level selling_plans metafield — see Show preorder shipping text on the cart page.

Purpose

  • Stores a per-variant override of the offer's shipping/delivery text, as a plain string.
  • Only populated when a per-variant override has been entered (see the note above); otherwise read the offer-level text from the shop-level selling_plans metafield.
  • Per-market overrides live in a separate market_shipping_text metafield (json, keyed by Shopify market id) — not in this field.

Accessing in Liquid

{% comment %} Present only if a per-variant override was set on this variant. {% endcomment %}
{% assign variant_shipping = product_variant.metafields.restockrocket_production.shipping_text.value %}

Here's an example of how to access the above metafields via GraphQL

Accessing via GraphQL

# Query to get metafields for a specific product variant
{
  productVariant(id: "gid://shopify/ProductVariant/YOUR_VARIANT_ID") {
    metafields(
      namespace: "restockrocket_production",
      first: 10
    ) {
      edges {
        node {
          id
          namespace
          key
          value
          type
        }
      }
    }
  }
}

# Query to get specific metafields for multiple variants of a product
{
  product(id: "gid://shopify/Product/YOUR_PRODUCT_ID") {
    variants(first: 10) {
      edges {
        node {
          id
          title
          metafields(
            namespace: "restockrocket_production",
            keys: ["preorder_count", "preorder_max_count", "shipping_text"]
          ) {
            edges {
              node {
                id
                key
                value
                type
              }
            }
          }
        }
      }
    }
  }
}

Simple examples of using STOQ's variant-level metafields with basic Shopify liquid

  1. Use Case: Show current preorder count and remaining spots.
{% assign target_variant = product.selected_or_first_available_variant %}
{% assign preorder_count = target_variant.metafields.restockrocket_production.preorder_count | default: 0 %}
{% assign preorder_max_count = target_variant.metafields.restockrocket_production.preorder_max_count %}

{% if preorder_max_count %}
  {% assign remaining = preorder_max_count | minus: preorder_count %}

  <div class="inventory-counter">
    <h4>Preorder Status</h4>
    <p><strong>{{ preorder_count }}</strong> preordered</p>
    <p><strong>{{ remaining }}</strong> remaining</p>
  </div>
{% endif %}
  1. Use Case: Show a variant's shipping override, if one is set.

    shipping_text is a plain string and only exists when a per-variant override was entered (see the note above). For the offer's shipping text — what most stores want — read the shop-level selling_plans metafield instead, e.g. the cart-page recipe.

{% assign target_variant = product.selected_or_first_available_variant %}
{% assign variant_shipping = target_variant.metafields.restockrocket_production.shipping_text.value %}

<div class="variant-shipping">
  {% if variant_shipping != blank %}
    <p>{{ variant_shipping }}</p>
  {% endif %}
</div>