Get Started

Configuration

You can customise Back in Stock’s settings using a PHP configuration file. This is optional: each setting has a default, so you only need to include the values you want to change.

To override a setting, create craft-commerce-back-in-stock.php in your Craft project’s /config directory and return an array of setting names and values. For example, the following will change the name displayed in the control panel:

<?php

return [
    'pluginName' => 'Product Alerts',
];

All other settings keep their defaults. Add any further settings you want to change to the same array. The options below explain the available settings and their defaults. You can also manage many of these settings in the control panel under Back in Stock → Settings.

Configuration Options

General Settings

pluginName

The name displayed for the plugin in the control panel.

hasCpSection

Whether Back in Stock appears in the main control-panel navigation.

Delivery

notificationPolicy

Controls how many waiting customers are selected when a variant becomes available. Use 'stockMatched' to start with the oldest requests and limit the number according to the stock on hand, or 'all' to notify everyone waiting even when demand exceeds stock.

subscribersPerUnit

The number of oldest waiting subscribers selected for each available unit when notificationPolicy is 'stockMatched'. For example, stock of 3 with a value of 2 selects up to six subscribers. A value greater than 1 can account for notified customers who do not complete a purchase.

This field is shown in the control panel only when Notification Recipients is set to Match available stock.

stockFieldHandle

The handle of a numeric custom field on the variant to use instead of Commerce inventory. Set this in config/craft-commerce-back-in-stock.php when an ERP or warehouse integration stores stock in a custom field:

<?php

return [
    'stockFieldHandle' => 'warehouseStock',
    'stockThreshold' => 0,
];

The field controls availability, stock-matched recipient limits and the stock recorded in notification history, even when Commerce inventory tracking is disabled. Commerce checkout and inventory settings are unaffected. The value must exceed stockThreshold; fractional quantities are rounded down to whole units. Empty values count as zero. A missing field or invalid numeric value is treated as unavailable and logs an error instead of falling back to Commerce stock.

Use a field available on every subscribed variant's field layout. Its value is read in the variant's site context; it does not sum Commerce inventory locations. For sites sharing a Commerce store, keep the field's stock quantity consistent across those sites. includeAvailableForPurchase still applies when enabled.

Saving a variant queues an availability check when customers are waiting for it. Integrations that bypass element saves should run the scheduled check after syncing. Use craft.backInStock.isVariantInStock(variant) in storefront form conditions so they follow the same field and threshold; see Example Form. Leave this setting null or empty to use Commerce inventory.

stockThreshold

The native or custom stock level a variant must exceed before it is considered available. With the default of 0, the variant needs at least one unit in stock.

includeAvailableForPurchase

Whether Commerce must also consider a variant available for purchase before Back in Stock sends notifications.

batchSize

The maximum number of selected emails scheduled together through Craft’s queue.

batchDelay

The delay in seconds before each additional notification batch is scheduled. A value of 0 schedules every batch immediately.

maximumAttempts

The maximum number of delivery attempts for a notification that definitely failed. Sending results that cannot be confirmed are retained for review and are not retried automatically because the mail transport may already have accepted the message.

Subscription

requireVerification

Whether a new subscription must be confirmed through a signed email link before it can receive an availability notification.

verificationWindow

The number of hours after subscribing that a customer can use the emailed verification link. Once this window closes, the link can no longer activate the request.

This field is shown in the control panel only when Require Email Verification is enabled.

pendingExpiry

The number of days an unverified request can remain pending, counted from the last time a verification email was requested, before it is marked expired. Expired requests cannot receive notifications and no longer prevent the customer from subscribing again. Use a period at least as long as verificationWindow.

This field is shown in the control panel only when Require Email Verification is enabled.

activeExpiry

The number of days a waiting request can remain without a successful availability notification before it is marked expired. Expired requests cannot receive notifications and the customer can subscribe again. Requests that existed before upgrading to 4.2 count from the upgrade.

historyRetention

The number of days notified, cancelled, and expired requests remain visible under Products before they are removed. Pending and waiting requests are unaffected. Requests completed before upgrading to 4.2 count from the upgrade. Use 0 to retain completed history indefinitely.

Email

sendConfirmation

Whether to send a confirmation after an immediately active subscription is created. When email verification is required, Back in Stock sends the verification message instead.

fromEmail

The sender email address. Environment variables and aliases are supported. When omitted, Craft’s system email address is used.

fromName

The sender name. Environment variables and aliases are supported. When omitted, Craft’s system sender name is used.

confirmationEmailTemplate

An optional site Twig template that completely replaces the back_in_stock_confirmation System Message body. The template receives variant, subscription, options, cancelUrl, and subject.

confirmationEmailSubject

The Twig-enabled subject used with confirmationEmailTemplate. Craft’s editable System Message subject is used when no custom template is configured.

emailTemplate

An optional site Twig template that completely replaces the back_in_stock_available System Message body. It receives the same variables as the confirmation template.

emailSubject

The Twig-enabled subject used with emailTemplate. Craft’s editable System Message subject is used when no custom template is configured.