> 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/shop-level-metafields.md).

# Shop Level Metafields

### Selling Plans Metafield

**Configuration**

* Key: `selling_plans`
* Type: `json`
* Namespace: `restockrocket_production`
* Owner: Shop

**Purpose**

Stores the complete configuration of all enabled selling plans (preorder offers) for a shop.

**Fields**

```json
{
  "shopify_selling_plan_group_id": "string",  // Unique identifier for the selling plan group in Shopify
  "shopify_selling_plan_id": "string",        // Unique identifier for the specific selling plan in Shopify
  "enabled": boolean,                         // Whether the selling plan is active
  "variant_ids": ["string"],                 // List of product variant IDs associated with this plan
  "name": "string",                          // Display name of the selling plan
  "preorder_button_text": "string",          // Text shown on the preorder button
  "preorder_button_description": "string",    // Description shown below the preorder button
  "preorder_button_description_background_color": "string",  // Background color of the description box
  "preorder_button_description_text_color": "string",        // Text color of the description
  "preorder_button_description_border_radius": "number",     // Border radius of the description box
  "preorder_button_description_show_quantity_limit": boolean,  // Whether to show quantity limits
  "preorder_button_description_quantity_limit_suffix": "string",  // Text after quantity limit
  "preorder_button_description_shipping_text_prefix": "string",   // Text before shipping info
  "delivery_exact_time": "string",           // Exact time of delivery
  "quantity_limit_text": "string",           // Text explaining quantity limitations
  "preorder_button_description_show_shipping": boolean,  // Whether to show shipping info
  "preorder_shipping_text": "string",        // Shipping information for preorder items
  "shipping_applies_to_all_products": boolean,  // Whether shipping settings are global
  "shipping_text": "string",                 // General shipping information
  "payment_type": "string",                  // Type of payment (full/partial)
  "billing_checkout_charge_type": "string",  // How the charge is calculated
  "billing_checkout_charge_amount": "number", // Fixed amount for checkout charge
  "billing_checkout_charge_percentage": "number",  // Percentage amount for checkout
  "pricing_type": "string",                  // Type of pricing adjustment
  "pricing_amount": "number",                // Fixed amount for pricing
  "pricing_percentage": "number",            // Percentage for pricing
  "discount_text": "string",                 // Text explaining discounts
  "billing_title": "string",                 // Title for billing information
  "billing_description": "string",           // Detailed billing information
  "enable_billing_widget": boolean,          // Whether to show billing widget
  "inventory_provider": "string",            // Provider handling inventory
  "preorder_badge_enabled": boolean,         // Whether to show preorder badge
  "preorder_badge_text": "string",           // Text shown on the badge
  "preorder_badge_text_color": "string",     // Color of badge text
  "preorder_badge_background_color": "string",  // Background color of badge
  "translations": {                          // Translations for multilingual support
    "locale_code": {
      "shipping_text": "string",
      "billing_title": "string",
      "billing_description": "string",
      "discount_text": "string",
      "preorder_badge_text": "string",
      "preorder_button_description": "string",
      "quantity_limit_text": "string",
      "preorder_shipping_text": "string",
      "preorder_button_text": "string"
    }
  }
}
```

**Accessing in Liquid**

```liquid
{% assign current_variant_id = product.selected_or_first_available_variant.id %}
{% assign selling_plans = shop.metafields.restockrocket_production.selling_plans.value %}
  
{% for plan in selling_plans %}
  {% if plan.enabled %}
    {% assign variant_ids = plan.variant_ids %}
    {% if variant_ids contains current_variant_id %}
      {% comment %}
        This variant is part of the selling plan
        You can now access plan details:
      {% endcomment %}
  
      <div class="preorder-button" style="background-color: {{ plan.preorder_badge_background_color }}">
        <span style="color: {{ plan.preorder_badge_text_color }}">
          {{ plan.preorder_badge_text }}
        </span>
      </div>
  
      {% if plan.preorder_button_description_show_quantity_limit %}
        {% assign preorder_count = product.selected_or_first_available_variant.metafields.restockrocket_production.preorder_count | default: 0 %}
        {% assign preorder_max_count = product.selected_or_first_available_variant.metafields.restockrocket_production.preorder_max_count %}
  
        {% if preorder_max_count %}
          {% assign remaining = preorder_max_count | minus: preorder_count %}
          <div class="quantity-limit">
            {{ remaining }}{{ plan.preorder_button_description_quantity_limit_suffix }}
          </div>
        {% endif %}
      {% endif %}
    {% endif %}
  {% endif %}
{% endfor %}
```

**Example: Working with Delivery Times**

```liquid
{% assign current_variant_id = product.selected_or_first_available_variant.id %}
{% assign selling_plans = shop.metafields.restockrocket_production.selling_plans.value %}

{% for plan in selling_plans %}
  {% if plan.enabled %}
    {% assign is_variant_in_plan = false %}
    {% for variant_id in plan.variant_ids %}
      {% if variant_id == current_variant_id %}
        {% assign is_variant_in_plan = true %}
        {% break %}
      {% endif %}
    {% endfor %}

    {% if is_variant_in_plan and plan.delivery_exact_time %}
      {% assign delivery_date = plan.delivery_exact_time | date: '%Y-%m-%d' | date: '%s' %}
      {% assign today_date = 'now' | date: '%Y-%m-%d' | date: '%s' %}
      {% assign seconds_diff = delivery_date | minus: today_date %}
      {% assign days_until_delivery = seconds_diff | divided_by: 86400 %}

      <div class="delivery-info">
        <h4>Delivery Information</h4>

        {% if days_until_delivery > 0 %}
          <p class="estimated-delivery">
            Estimated delivery: {{ plan.delivery_exact_time | date: '%B %d, %Y' }}
            <span class="days-left">({{ days_until_delivery }} days left)</span>
          </p>

          {% if plan.preorder_shipping_text %}
            {% assign formatted_date = plan.delivery_exact_time | date: '%B %d, %Y' %}
            {% capture date %}{{ formatted_date | escape }}{% endcapture %}
            <p class="shipping-note">
              {{ plan.preorder_shipping_text | url_escape | replace: "%7B%7B%20date%20%7D%7D", date | replace: "%20", " " }}
            </p>
          {% endif %}
        {% else %}
          <p class="delivery-soon">
            Delivery date approaching
          </p>
        {% endif %}
      </div>
    {% endif %}
  {% endif %}
{% endfor %}
```

**Accessing via GraphQL**

```graphql
# Query to get shop selling plans metafield
{
  shop {
    metafield(namespace: "restockrocket_production", key: "selling_plans") {
      id
      namespace
      key
      value
      type
    }
  }
}

# Query to get multiple shop metafields at once
{
  shop {
    metafields(
      namespace: "restockrocket_production",
      first: 10
    ) {
      edges {
        node {
          id
          namespace
          key
          value
          type
        }
      }
    }
  }
}
```

This example demonstrates:

* Converting the delivery time to a readable format
* Calculating days remaining until delivery
* Displaying a formatted delivery date
* Replacing placeholders in shipping text
* Adding conditional styling based on delivery status
* Basic CSS styling for the delivery information

### Simple examples of using STOQ's shop-level metafields with Shopify liquid

#### Example 1: Basic Preorder Badge

**Use Case**: Show preorder badge when variant is part of a selling plan.

```liquid
{% assign current_variant_id = product.selected_or_first_available_variant.id %}
{% assign selling_plans = shop.metafields.restockrocket_production.selling_plans.value %}

{% for plan in selling_plans %}
  {% if plan.enabled and plan.preorder_badge_enabled %}
    {% if plan.variant_ids contains current_variant_id %}
      <div class="preorder-badge"
           style="background: {{ plan.preorder_badge_background_color }}; color: {{ plan.preorder_badge_text_color }};">
        {{ plan.preorder_badge_text }}
      </div>
    {% endif %}
  {% endif %}
{% endfor %}
```

#### Example 2: Preorder Button Text

**Use Case**: Use custom button text from selling plan configuration.

```liquid
{% assign current_variant_id = product.selected_or_first_available_variant.id %}
{% assign selling_plans = shop.metafields.restockrocket_production.selling_plans.value %}
{% assign button_text = "Preorder Now" %}

{% for plan in selling_plans %}
  {% if plan.enabled and plan.variant_ids contains current_variant_id %}
    {% assign button_text = plan.preorder_button_text %}
    {% break %}
  {% endif %}
{% endfor %}

<button class="preorder-button">{{ button_text }}</button>
```

#### Example 3: Show Remaining Quantity

**Use Case**: Display how many preorder spots are left.

```liquid
{% assign current_variant = product.selected_or_first_available_variant %}
{% assign selling_plans = shop.metafields.restockrocket_production.selling_plans.value %}

{% for plan in selling_plans %}
  {% if plan.enabled and plan.variant_ids contains current_variant.id and plan.preorder_button_description_show_quantity_limit %}
    {% assign preorder_count = current_variant.metafields.restockrocket_production.preorder_count | default: 0 %}
    {% assign preorder_max_count = current_variant.metafields.restockrocket_production.preorder_max_count %}

    {% if preorder_max_count %}
      {% assign remaining = preorder_max_count | minus: preorder_count %}
      <div class="quantity-info">
        <p>{{ remaining }}{{ plan.preorder_button_description_quantity_limit_suffix | default: ' left' }}</p>
      </div>
    {% endif %}
  {% endif %}
{% endfor %}
```

#### Example 4: Delivery Date Display

**Use Case**: Show estimated delivery date from selling plan.

```liquid

<div data-gb-custom-block data-tag="assign"></div>

<div data-gb-custom-block data-tag="assign"></div>

<div data-gb-custom-block data-tag="for">

  

<div data-gb-custom-block data-tag="if" data-expression='plan.enabled and plan.variant_ids contains current_variant_id and plan.delivery_exact_time'>
    <div class="delivery-info">
      <h4>Estimated Delivery</h4>
      <p>{{ plan.delivery_exact_time | date: '%B %d, %Y' }}</p>

      {% if plan.preorder_shipping_text %}
        <p>{{ plan.preorder_shipping_text | replace: '{{ date }}', plan.delivery_exact_time | date: '%B %d, %Y' }}</p>
      {% endif %}
    </div>
  </div>

</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/shop-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.
