Subscriptions
Commerce supports recurring revenue via subscriptions, a feature of some gateways.
Once you’ve added a payment gateway that supports subscriptions, navigate to
- Commerce
- Subscription Plans
# Plans
Plans are predefined connections to external products in a gateway. When you create a new plan, Commerce communicates with the gateway and provides a list of existing candidates. You must configure these links carefully for subscriptions to work as you expect.
Like gateways, plans are configured globally—but it is up to you where they are displayed in your front-end!
Plans have the following settings:
- Name
A user-facing label for the plan. This should be distinct among plans that will be exposed to customers; additional descriptive content can be attached via the Description setting.
- Handle
An identifier used in templates to load this specific plan.
- Description
Attach an entry to hold additional content. Plans themselves are not elements, so they do not have their own field layouts.
- Gateway
Select a gateway to display a list of its subscription products. If this menu is empty, you’ll need to create a gateway, first.
- Gateway plan
Choose the externally-defined “plan” to bind the Commerce plan to.
Gateways may use different, proprietary names for subscription products.
- Enabled for customers to select?
Determines whether or not customers can start new subscriptions based on this plan. Disabled plans are not returned via
craft.commerce.plans.getAllEnabledPlans()
. (This setting appears in the sidebar, outside the main form!)
# Capabilities
Subscription actions (like cancellation and switching plans) are handled in a gateway-agnostic way for your customers and administrators—but the underlying gateway does ultimately determine what actions are supported.
Currently, the only first-party gateway that fully implements subscriptions is Stripe (opens new window).
# Statuses
Commerce synthesizes subscription data into the following states:
- Trial
The subscription is within a predetermined trial period before its first billing cycle.
{% if subscription.onTrial %} Your trial lasts until {{ subscription.getTrialExpires()|date('short') }}. {% endif %}
- Active
The subscription is within a paid billing cycle (even if it’s set to cancel at the end of the current billing cycle).
{% if subscription.isActive %} Your subscription is in good standing, and your next payment will be on {{ subscription.nextPaymentDate()|date('short') }}. {% endif %}
- Canceled
The subscription is outside of a paid billing cycle and was canceled by the user.
{% if subscription.isCanceled %} Your subscription was canceled on {{ subscription.dateCanceled|date('short') }} and will expire on {{ subscription.nextPaymentDate|date('short') }}. {% endif %}
- Expired
The subscription is outside of a paid billing cycle and was marked as such by the gateway (either after a fixed number of billing cycles or a permanently-failed payment).
{% if subscription.isCanceled %} This subscription expired on {{ subscription.dateExpired|date('short') }}. {% endif %}
You can see where each of these status checks are useful on the Subscription Templates page.
Status properties may not be mutually exclusive!
For example, a subscription can be both onTrial
and have an active
status.
# Starting a Subscription
Subscriptions are created when a logged-in customer submits a form with a plan ID and a saved payment source from the same gateway.
The Subscription Templates page also includes information about canceling and switching plans.
# Deleting Subscriptions or Plans
# Gateways
Not all gateways permit deleting subscription plans. Some gateways allow it and preserve all existing subscriptions, while others do not. Regardless of individual gateway support, we recommended against deleting a subscription plan on the gateway because it might result in the loss of historical data.
If you wish to end support for a plan, you can disable it via its settings. Existing subscriptions will continue to work, but new ones cannot be started.
# Commerce
Commerce will attempt to delete all local subscription plans when a gateway is deleted. If any subscription—even an expired one—exists for a given plan, deletion will be prevented. Similarly, Commerce does not allow a user with active or expired subscriptions to be deleted.
# Querying Subscriptions
You can fetch subscriptions in your templates or PHP code using subscription queries.
Once you’ve created a subscription query, you can set parameters on it to narrow down the results, and then execute it by calling .all()
. An array of Subscription (opens new window) elements will be returned.
See Element Queries in the Craft docs to learn about how element queries work.
# Example
We can display all of the current user’s active subscriptions by doing the following:
- Create a subscription query with
craft.subscriptions()
. - Set the user and
status
parameters on it. - Fetch the subscriptions with
.all()
. - Loop through the subscriptions using a for (opens new window) tag to output their HTML.
{# Make sure someone is logged in: #}
{% requireLogin %}
{# Create a subscription query and set parameters: #}
{% set mySubscriptionQuery = craft.subscriptions()
.user(currentUser)
.status('active') %}
{# Fetch the subscriptions: #}
{% set subscriptions = mySubscriptionQuery.all() %}
{# Display the subscriptions, if there were results: #}
{% if subscriptions is not empty %}
<ul>
{% for subscription in subscriptions %}
<li>
<strong>{{ subscription.title }}</strong>
{% if subscription.isCanceled %}
Canceled on {{ subscription.dateCanceled|date('short') }}, ending on {{ subscription.nextPaymentDate|date('short') }}.
{% else %}
Renews on {{ subscription.nextPaymentDate|date('short') }}
{% endif %}
</li>
{% endfor %}
</ul>
{% else %}
<p>You do not have any active subscriptions.</p>
<a href="{{ siteUrl('my-account/membership') }}">Join now</a>
{% endif %}
# Parameters
Subscription queries support the following parameters:
Param | Description |
---|---|
andNotRelatedTo | Narrows the query results to only subscriptions that are not related to certain other elements. |
andRelatedTo | Narrows the query results to only subscriptions that are related to certain other elements. |
andWith | Causes the query to return matching subscriptions eager-loaded with related elements, in addition to the elements that were already specified by with. |
asArray | Causes the query to return matching subscriptions as arrays of data, rather than Subscription (opens new window) objects. |
cache | Enables query cache for this Query. |
canonicalsOnly | Narrows the query results to only canonical elements, including elements that reference another canonical element via canonicalId so long as they aren’t a draft. |
clearCachedResult | Clears the cached result (opens new window). |
dateCanceled | Narrows the query results based on the subscriptions’ cancellation date. |
dateCreated | Narrows the query results based on the subscriptions’ creation dates. |
dateExpired | Narrows the query results based on the subscriptions’ expiration date. |
dateSuspended | Narrows the query results based on the subscriptions’ suspension date. |
dateUpdated | Narrows the query results based on the subscriptions’ last-updated dates. |
eagerly | Causes the query to be used to eager-load results for the query’s source element and any other elements in its collection. |
fixedOrder | Causes the query results to be returned in the order specified by id. |
gatewayId | Narrows the query results based on the gateway, per its ID. |
getFieldLayouts | Returns the field layouts that could be associated with the resulting elements. |
hasStarted | Narrows the query results to only subscriptions that have started. |
id | Narrows the query results based on the subscriptions’ IDs. |
ignorePlaceholders | Causes the query to return matching subscriptions as they are stored in the database, ignoring matching placeholder elements that were set by craft\services\Elements::setPlaceholderElement() (opens new window). |
inBulkOp | Narrows the query results to only subscriptions that were involved in a bulk element operation. |
inReverse | Causes the query results to be returned in reverse order. |
isCanceled | Narrows the query results to only subscriptions that are canceled. |
isExpired | Narrows the query results to only subscriptions that have expired. |
isSuspended | Narrows the query results to only subscriptions that are suspended. |
language | Determines which site(s) the subscriptions should be queried in, based on their language. |
limit | Determines the number of subscriptions that should be returned. |
nextPaymentDate | Narrows the query results based on the subscriptions’ next payment dates. |
notRelatedTo | Narrows the query results to only subscriptions that are not related to certain other elements. |
offset | Determines how many subscriptions should be skipped in the results. |
onTrial | Narrows the query results to only subscriptions that are on trial. |
orderBy | Determines the order that the subscriptions should be returned in. (If empty, defaults to dateCreated DESC .) |
orderId | Narrows the query results based on the order, per its ID. |
plan | Narrows the query results based on the subscription plan. |
planId | Narrows the query results based on the subscription plans’ IDs. |
preferSites | If unique() (opens new window) is set, this determines which site should be selected when querying multi-site elements. |
prepForEagerLoading | Prepares the query for lazy eager loading. |
prepareSubquery | Prepares the element query and returns its subquery (which determines what elements will be returned). |
reference | Narrows the query results based on the reference. |
relatedTo | Narrows the query results to only subscriptions that are related to certain other elements. |
render | Executes the query and renders the resulting elements using their partial templates. |
search | Narrows the query results to only subscriptions that match a search query. |
siteSettingsId | Narrows the query results based on the subscriptions’ IDs in the elements_sites table. |
status | Narrows the query results based on the subscriptions’ statuses. |
trashed | Narrows the query results to only subscriptions that have been soft-deleted. |
trialDays | Narrows the query results based on the number of trial days. |
uid | Narrows the query results based on the subscriptions’ UIDs. |
user | Narrows the query results based on the subscriptions’ user accounts. |
userId | Narrows the query results based on the subscriptions’ user accounts’ IDs. |
wasCountEagerLoaded | Returns whether the query result count was already eager loaded by the query's source element. |
wasEagerLoaded | Returns whether the query results were already eager loaded by the query's source element. |
with | Causes the query to return matching subscriptions eager-loaded with related elements. |
withCustomFields | Sets whether custom fields should be factored into the query. |
withProvisionalDrafts | Causes the query to return provisional drafts for the matching elements, when they exist for the current user. |
# andNotRelatedTo
Defined by craft\elements\db\ElementQuery
Narrows the query results to only subscriptions that are not related to certain other elements.
See Relations (opens new window) for a full explanation of how to work with this parameter.
{# Fetch all subscriptions that are related to myCategoryA and not myCategoryB #}
{% set subscriptions = craft.subscriptions()
.relatedTo(myCategoryA)
.andNotRelatedTo(myCategoryB)
.all() %}
# andRelatedTo
Defined by craft\elements\db\ElementQuery
Narrows the query results to only subscriptions that are related to certain other elements.
See Relations (opens new window) for a full explanation of how to work with this parameter.
{# Fetch all subscriptions that are related to myCategoryA and myCategoryB #}
{% set subscriptions = craft.subscriptions()
.relatedTo(myCategoryA)
.andRelatedTo(myCategoryB)
.all() %}
# andWith
Defined by craft\elements\db\ElementQuery
Causes the query to return matching subscriptions eager-loaded with related elements, in addition to the elements that were already specified by with.
.
# asArray
Defined by craft\elements\db\ElementQuery
Causes the query to return matching subscriptions as arrays of data, rather than Subscription (opens new window) objects.
{# Fetch subscriptions as arrays #}
{% set subscriptions = craft.subscriptions()
.asArray()
.all() %}
# cache
Defined by craft\elements\db\ElementQuery
Enables query cache for this Query.
# canonicalsOnly
Defined by craft\elements\db\ElementQuery
Narrows the query results to only canonical elements, including elements
that reference another canonical element via canonicalId
so long as they
aren’t a draft.
Unpublished drafts can be included as well if drafts(null)
and
draftOf(false)
are also passed.
# clearCachedResult
Defined by craft\elements\db\ElementQuery
Clears the cached result (opens new window).
# dateCanceled
Narrows the query results based on the subscriptions’ cancellation date.
Possible values include:
Value | Fetches subscriptions… |
---|---|
'>= 2018-04-01' | that were canceled on or after 2018-04-01. |
'< 2018-05-01' | that were canceled before 2018-05-01 |
['and', '>= 2018-04-04', '< 2018-05-01'] | that were canceled between 2018-04-01 and 2018-05-01. |
{# Fetch subscriptions that were canceled recently #}
{% set aWeekAgo = date('7 days ago')|atom %}
{% set subscriptions = craft.subscriptions()
.dateCanceled(">= #{aWeekAgo}")
.all() %}
# dateCreated
Defined by craft\elements\db\ElementQuery
Narrows the query results based on the subscriptions’ creation dates.
Possible values include:
Value | Fetches subscriptions… |
---|---|
'>= 2018-04-01' | that were created on or after 2018-04-01. |
'< 2018-05-01' | that were created before 2018-05-01. |
['and', '>= 2018-04-04', '< 2018-05-01'] | that were created between 2018-04-01 and 2018-05-01. |
now /today /tomorrow /yesterday | that were created at midnight of the specified relative date. |
{# Fetch subscriptions created last month #}
{% set start = date('first day of last month')|atom %}
{% set end = date('first day of this month')|atom %}
{% set subscriptions = craft.subscriptions()
.dateCreated(['and', ">= #{start}", "< #{end}"])
.all() %}
# dateExpired
Narrows the query results based on the subscriptions’ expiration date.
Possible values include:
Value | Fetches subscriptions… |
---|---|
'>= 2018-04-01' | that expired on or after 2018-04-01. |
'< 2018-05-01' | that expired before 2018-05-01 |
['and', '>= 2018-04-04', '< 2018-05-01'] | that expired between 2018-04-01 and 2018-05-01. |
{# Fetch subscriptions that expired recently #}
{% set aWeekAgo = date('7 days ago')|atom %}
{% set subscriptions = craft.subscriptions()
.dateExpired(">= #{aWeekAgo}")
.all() %}
# dateSuspended
Narrows the query results based on the subscriptions’ suspension date.
Possible values include:
Value | Fetches subscriptions… |
---|---|
'>= 2018-04-01' | that were suspended on or after 2018-04-01. |
'< 2018-05-01' | that were suspended before 2018-05-01 |
['and', '>= 2018-04-04', '< 2018-05-01'] | that were suspended between 2018-04-01 and 2018-05-01. |
{# Fetch subscriptions that were suspended recently #}
{% set aWeekAgo = date('7 days ago')|atom %}
{% set subscriptions = craft.subscriptions()
.dateSuspended(">= #{aWeekAgo}")
.all() %}
# dateUpdated
Defined by craft\elements\db\ElementQuery
Narrows the query results based on the subscriptions’ last-updated dates.
Possible values include:
Value | Fetches subscriptions… |
---|---|
'>= 2018-04-01' | that were updated on or after 2018-04-01. |
'< 2018-05-01' | that were updated before 2018-05-01. |
['and', '>= 2018-04-04', '< 2018-05-01'] | that were updated between 2018-04-01 and 2018-05-01. |
now /today /tomorrow /yesterday | that were updated at midnight of the specified relative date. |
{# Fetch subscriptions updated in the last week #}
{% set lastWeek = date('1 week ago')|atom %}
{% set subscriptions = craft.subscriptions()
.dateUpdated(">= #{lastWeek}")
.all() %}
# eagerly
Defined by craft\elements\db\ElementQuery
Causes the query to be used to eager-load results for the query’s source element and any other elements in its collection.
# fixedOrder
Defined by craft\elements\db\ElementQuery
Causes the query results to be returned in the order specified by id.
If no IDs were passed to id, setting this to true
will result in an empty result set.
{# Fetch subscriptions in a specific order #}
{% set subscriptions = craft.subscriptions()
.id([1, 2, 3, 4, 5])
.fixedOrder()
.all() %}
# gatewayId
Narrows the query results based on the gateway, per its ID.
Possible values include:
Value | Fetches subscriptions… |
---|---|
1 | with a gateway with an ID of 1. |
'not 1' | not with a gateway with an ID of 1. |
[1, 2] | with a gateway with an ID of 1 or 2. |
['not', 1, 2] | not with a gateway with an ID of 1 or 2. |
# getFieldLayouts
Defined by craft\elements\db\ElementQuery
Returns the field layouts that could be associated with the resulting elements.
# hasStarted
Narrows the query results to only subscriptions that have started.
{# Fetch started subscriptions #}
{% set subscriptions = craft.subscriptions()
.hasStarted()
.all() %}
# id
Defined by craft\elements\db\ElementQuery
Narrows the query results based on the subscriptions’ IDs.
Possible values include:
Value | Fetches subscriptions… |
---|---|
1 | with an ID of 1. |
'not 1' | not with an ID of 1. |
[1, 2] | with an ID of 1 or 2. |
['not', 1, 2] | not with an ID of 1 or 2. |
{# Fetch the subscription by its ID #}
{% set subscription = craft.subscriptions()
.id(1)
.one() %}
This can be combined with fixedOrder if you want the results to be returned in a specific order.
# ignorePlaceholders
Defined by craft\elements\db\ElementQuery
Causes the query to return matching subscriptions as they are stored in the database, ignoring matching placeholder elements that were set by craft\services\Elements::setPlaceholderElement() (opens new window).
# inBulkOp
Defined by craft\elements\db\ElementQuery
Narrows the query results to only subscriptions that were involved in a bulk element operation.
# inReverse
Defined by craft\elements\db\ElementQuery
Causes the query results to be returned in reverse order.
{# Fetch subscriptions in reverse #}
{% set subscriptions = craft.subscriptions()
.inReverse()
.all() %}
# isCanceled
Narrows the query results to only subscriptions that are canceled.
{# Fetch canceled subscriptions #}
{% set subscriptions = craft.subscriptions()
.isCanceled()
.all() %}
# isExpired
Narrows the query results to only subscriptions that have expired.
{# Fetch expired subscriptions #}
{% set subscriptions = craft.subscriptions()
.isExpired()
.all() %}
# isSuspended
Narrows the query results to only subscriptions that are suspended.
{# Fetch suspended subscriptions #}
{% set subscriptions = craft.subscriptions()
.isSuspended()
.all() %}
# language
Defined by craft\elements\db\ElementQuery
Determines which site(s) the subscriptions should be queried in, based on their language.
Possible values include:
Value | Fetches subscriptions… |
---|---|
'en' | from sites with a language of en . |
['en-GB', 'en-US'] | from sites with a language of en-GB or en-US . |
['not', 'en-GB', 'en-US'] | not in sites with a language of en-GB or en-US . |
Elements that belong to multiple sites will be returned multiple times by default. If you only want unique elements to be returned, use unique() (opens new window) in conjunction with this.
{# Fetch subscriptions from English sites #}
{% set subscriptions = craft.subscriptions()
.language('en')
.all() %}
# limit
Determines the number of subscriptions that should be returned.
{# Fetch up to 10 subscriptions #}
{% set subscriptions = craft.subscriptions()
.limit(10)
.all() %}
# nextPaymentDate
Narrows the query results based on the subscriptions’ next payment dates.
Possible values include:
Value | Fetches subscriptions… |
---|---|
'>= 2018-04-01' | with a next payment on or after 2018-04-01. |
'< 2018-05-01' | with a next payment before 2018-05-01 |
['and', '>= 2018-04-04', '< 2018-05-01'] | with a next payment between 2018-04-01 and 2018-05-01. |
{# Fetch subscriptions with a payment due soon #}
{% set aWeekFromNow = date('+7 days')|atom %}
{% set subscriptions = craft.subscriptions()
.nextPaymentDate("< #{aWeekFromNow}")
.all() %}
# notRelatedTo
Defined by craft\elements\db\ElementQuery
Narrows the query results to only subscriptions that are not related to certain other elements.
See Relations (opens new window) for a full explanation of how to work with this parameter.
{# Fetch all subscriptions that are related to myEntry #}
{% set subscriptions = craft.subscriptions()
.notRelatedTo(myEntry)
.all() %}
# offset
Determines how many subscriptions should be skipped in the results.
{# Fetch all subscriptions except for the first 3 #}
{% set subscriptions = craft.subscriptions()
.offset(3)
.all() %}
# onTrial
Narrows the query results to only subscriptions that are on trial.
{# Fetch trialed subscriptions #}
{% set subscriptions = craft.subscriptions()
.onTrial()
.all() %}
# orderBy
Defined by craft\elements\db\ElementQuery
Determines the order that the subscriptions should be returned in. (If empty, defaults to dateCreated DESC
.)
{# Fetch all subscriptions in order of date created #}
{% set subscriptions = craft.subscriptions()
.orderBy('dateCreated ASC')
.all() %}
# orderId
Narrows the query results based on the order, per its ID.
Possible values include:
Value | Fetches subscriptions… |
---|---|
1 | with an order with an ID of 1. |
'not 1' | not with an order with an ID of 1. |
[1, 2] | with an order with an ID of 1 or 2. |
['not', 1, 2] | not with an order with an ID of 1 or 2. |
# plan
Narrows the query results based on the subscription plan.
Possible values include:
Value | Fetches subscriptions… |
---|---|
'foo' | for a plan with a handle of foo . |
['foo', 'bar'] | for plans with a handle of foo or bar . |
a Plan (opens new window) object | for a plan represented by the object. |
{# Fetch Supporter plan subscriptions #}
{% set subscriptions = craft.subscriptions()
.plan('supporter')
.all() %}
# planId
Narrows the query results based on the subscription plans’ IDs.
Possible values include:
Value | Fetches subscriptions… |
---|---|
1 | for a plan with an ID of 1. |
[1, 2] | for plans with an ID of 1 or 2. |
['not', 1, 2] | for plans not with an ID of 1 or 2. |
# preferSites
Defined by craft\elements\db\ElementQuery
If unique() (opens new window) is set, this determines which site should be selected when querying multi-site elements.
For example, if element “Foo” exists in Site A and Site B, and element “Bar” exists in Site B and Site C,
and this is set to ['c', 'b', 'a']
, then Foo will be returned for Site B, and Bar will be returned
for Site C.
If this isn’t set, then preference goes to the current site.
{# Fetch unique subscriptions from Site A, or Site B if they don’t exist in Site A #}
{% set subscriptions = craft.subscriptions()
.site('*')
.unique()
.preferSites(['a', 'b'])
.all() %}
# prepForEagerLoading
Defined by craft\elements\db\ElementQuery
Prepares the query for lazy eager loading.
# prepareSubquery
Defined by craft\elements\db\ElementQuery
Prepares the element query and returns its subquery (which determines what elements will be returned).
# reference
Narrows the query results based on the reference.
# relatedTo
Defined by craft\elements\db\ElementQuery
Narrows the query results to only subscriptions that are related to certain other elements.
See Relations (opens new window) for a full explanation of how to work with this parameter.
{# Fetch all subscriptions that are related to myCategory #}
{% set subscriptions = craft.subscriptions()
.relatedTo(myCategory)
.all() %}
# render
Defined by craft\elements\db\ElementQuery
Executes the query and renders the resulting elements using their partial templates.
If no partial template exists for an element, its string representation will be output instead.
# search
Defined by craft\elements\db\ElementQuery
Narrows the query results to only subscriptions that match a search query.
See Searching (opens new window) for a full explanation of how to work with this parameter.
{# Get the search query from the 'q' query string param #}
{% set searchQuery = craft.app.request.getQueryParam('q') %}
{# Fetch all subscriptions that match the search query #}
{% set subscriptions = craft.subscriptions()
.search(searchQuery)
.all() %}
# siteSettingsId
Defined by craft\elements\db\ElementQuery
Narrows the query results based on the subscriptions’ IDs in the elements_sites
table.
Possible values include:
Value | Fetches subscriptions… |
---|---|
1 | with an elements_sites ID of 1. |
'not 1' | not with an elements_sites ID of 1. |
[1, 2] | with an elements_sites ID of 1 or 2. |
['not', 1, 2] | not with an elements_sites ID of 1 or 2. |
{# Fetch the subscription by its ID in the elements_sites table #}
{% set subscription = craft.subscriptions()
.siteSettingsId(1)
.one() %}
# status
Narrows the query results based on the subscriptions’ statuses.
Possible values include:
Value | Fetches subscriptions… |
---|---|
'active' (default) | that are active. |
'expired' | that have expired. |
{# Fetch expired subscriptions #}
{% set subscriptions = craft.subscriptions()
.status('expired')
.all() %}
# trashed
Defined by craft\elements\db\ElementQuery
Narrows the query results to only subscriptions that have been soft-deleted.
{# Fetch trashed subscriptions #}
{% set subscriptions = craft.subscriptions()
.trashed()
.all() %}
# trialDays
Narrows the query results based on the number of trial days.
# uid
Defined by craft\elements\db\ElementQuery
Narrows the query results based on the subscriptions’ UIDs.
{# Fetch the subscription by its UID #}
{% set subscription = craft.subscriptions()
.uid('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
.one() %}
# user
Narrows the query results based on the subscriptions’ user accounts.
Possible values include:
Value | Fetches subscriptions… |
---|---|
'foo' | for a user account with a username of foo |
['foo', 'bar'] | for user accounts with a username of foo or bar . |
a User (opens new window) object | for a user account represented by the object. |
{# Fetch the current user's subscriptions #}
{% set subscriptions = craft.subscriptions()
.user(currentUser)
.all() %}
# userId
Narrows the query results based on the subscriptions’ user accounts’ IDs.
Possible values include:
Value | Fetches subscriptions… |
---|---|
1 | for a user account with an ID of 1. |
[1, 2] | for user accounts with an ID of 1 or 2. |
['not', 1, 2] | for user accounts not with an ID of 1 or 2. |
{# Fetch the current user's subscriptions #}
{% set subscriptions = craft.subscriptions()
.userId(currentUser.id)
.all() %}
# wasCountEagerLoaded
Defined by craft\elements\db\ElementQuery
Returns whether the query result count was already eager loaded by the query's source element.
# wasEagerLoaded
Defined by craft\elements\db\ElementQuery
Returns whether the query results were already eager loaded by the query's source element.
# with
Defined by craft\elements\db\ElementQuery
Causes the query to return matching subscriptions eager-loaded with related elements.
See Eager-Loading Elements (opens new window) for a full explanation of how to work with this parameter.
{# Fetch subscriptions eager-loaded with the "Related" field’s relations #}
{% set subscriptions = craft.subscriptions()
.with(['related'])
.all() %}
# withCustomFields
Defined by craft\elements\db\ElementQuery
Sets whether custom fields should be factored into the query.
# withProvisionalDrafts
Defined by craft\elements\db\ElementQuery
Causes the query to return provisional drafts for the matching elements, when they exist for the current user.