Skip to content

When a license is saved

Sends a notification when a Digital Product License is saved. Covers both new licenses (usually created the moment a customer's order is paid) and updates to existing ones.

This is the trigger to reach for when you want to email customers their license key. The License element shows up on event.sender, so the key, the buyer's email, the product, and the order are all available directly in your Twig body.

Requires Digital Products

Only available when the Digital Products plugin is installed.

Digital Product Type Filters

Choose which Digital Product types should fire this notification. Only products of the selected types will trigger it.

For license events, the filter checks the parent product's type instead.

Selection is required

Check at least one product type, or the notification won't fire.

Field Conditions

Field conditions restrict the notification based on the element's content, using Craft's native conditions framework. Build a rule set against the element's attributes and field values, and the notification will be sent only when every rule matches.

Must match all conditions

The condition builder evaluates every rule with AND semantics, so each rule must pass for the notification to be sent.

The "has changed" operator

Field rules now include an additional "has changed" operator, alongside the existing standard options.

When the element is saved, the "has changed" operator checks whether the field's value has changed during the save, (regardless of what the new value is). The notification will only be sent when the specified field's value has changed.

Twig variables

The object variable (and its license alias) is the saved License element. It carries:

  • licenseKey (string) - the actual key the customer uses
  • getProduct() - the Digital Product the license is tied to
  • getOrder() - the Commerce Order that created the license
  • getUser() - the Craft User (if the buyer was registered)
  • ownerName, ownerEmail - the buyer (guest checkout falls back to these)
  • getLicensedTo() - convenience: returns the user's email or the guest email
twig
"{{ license.product.title }}" license: {{ license.licenseKey }}

Examples

Send the customer their key on purchase

twig
Hi {{ license.licensedTo }},

Thanks for purchasing {{ license.product.title }}.

Your license key: {{ license.licenseKey }}

Download: {{ license.product.url }}

Alert admins of a new sale

twig
New license issued.

- Product: {{ license.product.title }}
- Customer: {{ license.licensedTo }}
- Order: #{{ license.order.shortNumber }}
- Total: {{ license.order.totalPrice|commerceCurrency }}

Skip licenses tied to internal test orders

twig
{% if license.order.email ends with '@internal.test' %}
    {% skipMessage "Internal test order; not announced." %}
{% endif %}

New license: {{ license.licenseKey }}