> For the complete documentation index, see [llms.txt](https://docs.stoqapp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stoqapp.com/preorder-metafields/product-variant-level-metafields.md).

# Product Variant Level Metafields

### 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

```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**

```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**

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

#### Example Usage: Preorder Count and Max count

```liquid
{% 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 %}

```

```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
              }
            }
          }
        }
      }
    }
  }
}
```

### 4. Shipping Text Metafield

**Configuration**

* Key: `shipping_text`
* Type: `json`
* Namespace: `restockrocket_production`
* Owner: Product Variant

**Purpose**

* Stores shipping/delivery timeline text for a product variant
* Stored as a JSON object with market IDs as keys and shipping text as values

**Accessing in Liquid**

```liquid
{% assign shipping_text = product_variant.metafields.restockrocket_production.shipping_text %}
```

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

#### Accessing via GraphQL

```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.

```liquid
{% 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 %}
```

2. **Use Case**: Show shipping info specific to the selected variant.

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

<div class="variant-shipping">
  <h4>Shipping Information</h4>

  {% if variant_shipping %}
    {% for shipping_info in variant_shipping %}
      <div>
        <strong>{{ shipping_info[0] | upcase }}:</strong>
        <p>{{ shipping_info[1] }}</p>
      </div>
    {% endfor %}
  {% else %}
    <p>Standard shipping rates apply</p>
  {% endif %}
</div>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.stoqapp.com/preorder-metafields/product-variant-level-metafields.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
