LogoLogo
  • πŸ› οΈWelcome to Smartrr help docs
  • Links
    • Changelog
    • API Docs
  • Getting Started
    • Implementation
      • πŸͺ„Installing Smartrr on a Shopify 2.0 theme (Automatic Install)
      • πŸ—ΊοΈInstalling Smartrr on a custom Shopify theme (Guided Install)
      • πŸ§Ÿβ€β™‚οΈInstalling Smartrr on a headless store
      • πŸ’»Adding Smartrr to a custom page (Shopify Liquid)
    • Onboarding
      • ⛑️Basic onboarding process
      • 🧀Smartrr team led onboarding
      • πŸ’΅Plans
      • πŸ’³Migrating subscriptions from payment processors
  • Support
    • Subscription Setup
      • πŸ“‡Subscription Programs
      • βš“Subscription anchor dates
      • πŸ—“οΈMaximum/minimum (finite) subscription plans
      • πŸ“§Email subscription notifications (Customer Notifications)
      • πŸ“²SMS subscription notifications (via Twilio)
      • πŸ›οΈSubscription discount codes
      • πŸ’ΈPrepaid subscriptions
      • πŸͺœSequential Flow Builder?
      • πŸ“¦Shipping methods
      • ❔Subscriptions when an item is unavailable
      • πŸ’²Buy-now-pay-later payment methods for subscriptions
      • 🏁Checkout Extensions
    • Admin Portal
      • πŸ”Adjusting customers’ subscriptions
      • πŸ“‡Adjusting customers' information
      • πŸ€Έβ€β™‚οΈ"View as customer" feature
      • πŸ•’Event log
      • πŸ“ŠAdvanced Analytics reporting
      • πŸ–ŒοΈCustomer account portal theming
      • πŸ”€Translations
      • πŸ’»Available actions for customers in account portal
      • 🎨CSS overrides
      • πŸ” Adjusting typography with CSS overrides
      • πŸ“£Marketing Banners
      • πŸ’­Retention
      • 🧺Bundles
      • 🎁Loyalty
      • πŸ”Passwordless login
      • πŸ’ŸCreator upsells
      • 🎞️Instagram feed
    • Customer Account Portal
      • πŸšͺAccessing the Customer Account Portal
      • πŸ”„Creating an account
      • πŸ”œViewing next orders
      • πŸ“Manage subscriptions
      • πŸ—ƒοΈOrder history
      • πŸ“§Updating email address
    • Transactions
      • 🀝Subscription transactions
      • 🚫Failed payments
      • πŸ“†Billing schedule
    • Integrations
      • 🌐Available integrations with Smartrr
      • πŸ“±Attentive x Smartrr Integration
      • πŸ“±Blueprint x Smartrr Integration
      • πŸ“¬Gorgias x Smartrr Integration
      • πŸ“©Klaviyo x Smartrr Integration
      • 🦁Loyalty Lion x Smartrr Integration
      • πŸ“±Postscript x Smartrr Integration
      • πŸ”Recharge x Smartrr Integration
      • 🟩Shopify Flow x Smartrr Integration
      • πŸͺWebhooks
    • Shopify Questions
      • πŸ’²Will updating product prices in Shopify reflect in Smartrr?
    • Developer Documentation
      • Bundles: Developer Documentation
      • Adding Metafields to Disable Add to Cart for OOS Products
    • Troubleshooting
      • ⏸️Why did my customer's subscription automatically pause?
      • πŸ“žWhy is my customer's shipping address invalid? (Phone number formatting)
      • πŸ†˜Can’t find the answer to your question?
    • RSS Feed
      • πŸ“³Smartrr’s changelog: Stay up-to-date with Slack
Powered by GitBook
On this page
  • Objective
  • Background
  • Purpose
  • How To Implement
  • Example Templates

Was this helpful?

Export as PDF
  1. Support
  2. Developer Documentation

Adding Metafields to Disable Add to Cart for OOS Products

PreviousBundles: Developer DocumentationNextTroubleshooting

Last updated 6 hours ago

Was this helpful?

Objective

This guide outlines how to replicate "Out of Stock" behavior on product display pages (PDPs) while still allowing subscription orders to be processed.

Background

Currently, for subscriptions to process orders that include products with negative inventory, the "Continue selling when out of stock" option must be enabled. However, enabling this setting also allows new, one-time purchases of these out-of-stock items, which may result in overselling.

Purpose

To address this, the following guide provides a method to simulate an "Out of Stock" state for one-time purchasesβ€”restricting new customers from buying unavailable itemsβ€”while still permitting existing, recurring subscription orders to process as usual.

How To Implement

  1. Create the Metafield

  2. Go to Settings > Custom data > Products in Shopify admin.

  1. Add a new definition

    • Name: Force Out of Stock (feel free to adjust as needed)

    • Key: force_out_of_stock (this will autopopulate from the name)

    • Type: Boolean (True/False)

  1. Set the Metafield for Specific Products

    • Navigate to a product that you want to β€œset out of stock” visually on the frontend.

    • Scroll to the metafields section at the bottom.

    • Set Force Out of Stock to true.

  1. Modify Your Theme Code

    • Go to Online Store > Themes > Edit Code

    • Find your product.liquid, main-product.liquid, or product.json template, depending on your theme.

    • Locate your purchase button (i.e. add to cart button or buy button).

    • Modify the display of the purchase button based on the Force Out of Stock metafield.

      • When this metafield is enabled, a disabled version of the "Buy" button should be shown to simulate an out-of-stock state.

      • If the metafield is not enabled, the standard "Buy" button should be displayed as usual.

Example Templates

Example 1

{% if product.metafields.custom.force_out_of_stock == true %}
  <p class="product__inventory">Out of stock</p>
  <button class="btn btn--disabled" disabled>Sold Out</button>
{% else %}
  <!-- Normal inventory logic -->
  {% if product.available %}
    <button class="btn">Add to cart</button>
  {% else %}
    <button class="btn btn--disabled" disabled>Sold Out</button>
  {% endif %}
{% endif %}

Example 2 (in product-form.liquid)

// some styling to disable the button 
<style>
  .out-of-stock-btn {
  pointer-events: none;
  opacity: 0.8; 
  cursor: not-allowed;
}
</style>
      
[... rest of code here]     
{% if product.metafields.custom.force_out_of_stock == true %}
// displaying an out of stock button with disabled styling
     <div class="product-form__submit-wrapper">
         <button class="no-style btn btn--action btn--full out-of-stock-btn" disabled>
          Out of Stock
        </button>
     </div>
  {% else %}
// displaying their default add to cart button
      <div class="product-form__submit-wrapper">
        <button type="submit" class="product__submit no-style btn btn--action btn--full"
          {% if settings.cartType == 'drawer' %}onclick="ajaxCart(this)"{% endif %}
          name="add"
          data-product-submit
        >
          <span class="visually-hidden">{{ product.title }} &mdash; <span data-product-price-cta></span></span>
          {% if product.type == 'Custom Bundle' %}
            <span data-product-submit-text>
              <span class="product-form__bundle-atc-price">
                <span data-product-price-cta>
                {%- liquid
                  if display_subscription_options and product.selling_plan_groups.size > 0 
                    echo product.selected_or_first_available_variant.selling_plan_allocations[0].price | money_without_trailing_zeros 
                  else 
                    echo product.selected_or_first_available_variant.price | money_without_trailing_zeros 
                  endif 
                -%}
                </span>
                {% if product.selected_or_first_available_variant.compare_at_price > product.selected_or_first_available_variant.price %}
                  <s data-product-compare-price-cta>{{ product.selected_or_first_available_variant.compare_at_price | money_without_trailing_zeros }}</s>
                {% endif %} -
              </span>
              {{ 'product.add_to_cart' | t }}
            </span>
          {% else %}
            <span data-product-submit-text><span data-product-price-cta>{{ product.selected_or_first_available_variant.price | money_without_trailing_zeros }}</span> – {{ 'product.add_to_cart' | t }}</span>
          {% endif %}

          <span x-grid columns="1" pi="center" class="loading-overlay__spinner hidden">{{ 'product.addingToCart' | t }}</span>
        </button>
      </div>
    {% endif %}