Commerce Events (Extension Development)
The domain events your extension's transformers produce — constructor signatures and extension-specific guidance.
WordPress plugin
Last updated: October 28, 2026
Commerce events are the domain events your extension produces when something happens in the integrated platform. This includes sales, refunds, and coupon applications. Your transformer returns one of these event instances (or null to skip), and Siren’s core handles everything downstream. See Event Bindings and Transformers for how to wire these into your Integration class.
All commerce events live in Siren\Commerce\Events\ and implement PHPNomad’s Event interface. Extensions never dispatch these events directly. They return them from transformer callbacks, and the framework broadcasts them.
What happens when a sale is detected?
SaleTriggered is the primary entry point for the entire conversion pipeline. When your transformer determines that an order should be tracked, it returns a SaleTriggered instance carrying the opportunity, the line items, and a reference back to the external order.
return new SaleTriggered(
$opportunity->getId(), // which affiliate referral led to this sale
$transactionDetails, // line items from your adapter (array of detail arrays)
'wc', // your extension's ID (matches Integration::getId())
$orderId, // external order ID for mapping back to the platform
'wc_order' // external type identifier for the mapping table
);
The $transactionDetails array comes from your adapter’s toArray() method. Each element represents a line item with a name, description, type, per-unit value in cents, quantity, and currency code. See the Adapters guide for the full format.
Once SaleTriggered broadcasts, Siren’s core creates the transaction, evaluates which programs apply, builds conversion records, and generates obligations. Your extension’s job ends at producing the event. See the SaleTriggered event reference for full payload and listener details.
The transformer is responsible for three checks before returning this event: locating the affiliate opportunity for the customer, verifying the order hasn’t already been processed (via the mapping table), and confirming the order has line items. If any check fails, return null.
How does Siren know when payment is confirmed?
TransactionCompleted fires when an order reaches its final approved state. This typically happens when a payment gateway confirms the charge. This is separate from SaleTriggered because many platforms create orders before payment clears.
return new TransactionCompleted($transaction);
The transformer for this event is simpler than the sale transformer. It looks up the existing Siren transaction by querying the mapping table for the external order ID, then wraps it in the event. If no mapping exists (the order was never tracked by Siren), return null.
When this event fires, Siren approves the associated conversions in programs that auto-approve, which moves their obligations from draft to approved and makes them eligible for payout. A conversion whose reward is held because the sale is in another currency stays pending. See the TransactionCompleted event reference for full details.
What triggers a refund?
RefundTriggered fires when a completed order is reversed. This could be an explicit refund, a cancellation, or an admin trashing the order.
return new RefundTriggered($transaction);
Like TransactionCompleted, the transformer looks up the Siren transaction via the mapping table. If no mapping exists, the order was never tracked, so there’s nothing to refund. Return null.
When this event fires, Siren cancels all conversions tied to the transaction, marks the transaction as refunded, and adjusts incentive and distribution metrics. See the RefundTriggered event reference for full details. You typically bind this to multiple platform hooks to cover all the ways an order can be reversed:
RefundTriggered::class => [
['action' => 'woocommerce_order_status_completed_to_failed', 'transformer' => $refundCallback],
['action' => 'woocommerce_order_status_completed_to_cancelled', 'transformer' => $refundCallback],
['action' => 'woocommerce_order_status_completed_to_refunded', 'transformer' => $refundCallback],
['action' => 'wc-completed_to_trash', 'transformer' => $refundCallback],
],
How do coupon codes create engagements?
CouponApplied fires when a customer uses a coupon code during checkout. This event exists specifically to create an engagement that links the coupon code back to the collaborator who owns it.
return new CouponApplied($couponCode, $opportunity, 'wc');
Two things to note: Siren matches coupon codes without regard to case, so you can pass the code as the platform reports it, and the third argument names the integration (such as wc, edd, llms, or nc) so Siren checks that integration’s coupons first. This transformer also uses CurrentUserOpportunity locators instead of VisitorOpportunity because the coupon is applied by the logged-in customer during checkout, not tied to a specific order.
When this event fires, Siren’s BoundCouponUsed engagement trigger strategy looks up the collaborator the coupon code credits in Siren’s coupon records, then creates engagements for every active program that collaborator participates in with the boundCouponUsed trigger enabled. See the CouponApplied event reference for full details.
How are subscription renewals tracked?
RenewalTriggered fires when a subscription renewal payment completes. This is the most complex commerce event because it needs to link back to the original transaction so commissions continue on recurring revenue.
return new RenewalTriggered(
$originalTransaction, // the Siren transaction from the initial purchase
$transactionDetails, // line items for the renewal order
$orderId, // int|string|null: external renewal record ID
'wc_order' // external type
);
The transformer must trace the renewal order back to the original subscription’s first order, then look up the Siren transaction for that original order via the mapping table. It also performs the standard duplicate check on the renewal order ID.
Renewal support is conditional. WooCommerce only adds the binding when WooCommerce Subscriptions is installed:
if (class_exists(WC_Subscription::class)) {
$triggers[RenewalTriggered::class] = [
['action' => 'woocommerce_subscription_renewal_payment_complete',
'transformer' => $renewalCallback],
];
}
See the RenewalTriggered event reference for full details.
What about leads and form submissions?
LeadTriggered is the non-monetary equivalent of SaleTriggered. It fires when a form submission or signup action occurs, carrying an opportunity ID and source identifier but no transaction details (leads have no monetary value at trigger time).
Form-based integrations like Gravity Forms use this event instead of SaleTriggered. The downstream pipeline creates conversions and obligations using the lead incentive type rather than sale-based incentive types. See the LeadTriggered event reference for full details.
How does an integration spend store credit?
Store credit lets a collaborator spend their balance in a custom currency at the store’s checkout. Siren keeps the balance in its ledger, and the store’s integration handles the checkout. The WooCommerce, Easy Digital Downloads, and LifterLMS integrations each ship a store credit add-on for this, and only Siren Essentials and up include them. Every add-on takes the same seven steps, and the WooCommerce add-on (Siren\WordPress\Extensions\WooCommerce\StoreCredit\StoreCreditAddOn) is the worked example here.
- Declare
Features::CreditRedemptioningetSupports(), so Siren knows the store can spend credit. See Feature Flags. - Register a credit coupon strategy and a checkout session locator. Listen for
CreditCouponStrategyRegistryInitiatedand calladdStrategy()with a class that implementsCreditCouponStrategy, which makes, applies, and deletes the store’s credit coupons. Listen forCheckoutSessionLocatorRegistryInitiatedand calladdLocator()with a class that implementsCheckoutSessionLocator, which keeps a hold token for each checkout. Both classes return the same platform ID fromgetId(), such aswoocommerce. - Register a checkout filter at boot. Listen for
Readyand hook the platform’s coupon amount filter,woocommerce_coupon_get_amountin WooCommerce. The filter sets the credit coupon’s amount fromCreditCheckoutService::getFilteredAmount(), which reads the shopper’s live balance less the credit other checkouts hold. Pass it the current session’s hold reference,HoldService::referenceFor($platformId, $token), so the shopper’s own hold isn’t subtracted. Siren creates credit coupons with no amount, so without this filter the coupon takes nothing off. Subtracting other checkouts’ holds is what keeps two checkouts from spending the same balance. - Fire
CreditAutoApplyRequestedwith the shopper’s user ID and your platform ID when the cart or checkout loads. Siren applies the shopper’s credit coupons and holds their credit under the session’s token. - Stamp the hold token on the order when the order is created. Read it with the locator’s
peekToken(), which never makes a new token, and save it withstampOrder(). - Fire
OrderDiscountsDetectedwhen the order completes, and pass the locator’sgetTokenForOrder()as the hold token. Siren takes the credit and marks the checkout’s holds settled. Without the token, the holds stay active until they expire, and the shopper’s credit counts twice until then. - Fire
OrderDiscountsReversedwhen the order is refunded, and when it’s cancelled where the platform has that status, with the same platform reference, so Siren can give the credit back.
The add-on wires all seven steps from four methods. This is the WooCommerce add-on, shortened:
class StoreCreditAddOn implements ExtensionAddOn, HasEventBindings, HasListeners, CanSetContainer, Loadable
{
use HasSettableContainer;
public static function getExtensionId(): string
{
return Integration::getId();
}
public function getSupports(): array
{
return [Features::CreditRedemption];
}
public function getListeners(): array
{
return [
CreditCouponStrategyRegistryInitiated::class => RegisterWooCommerceCreditCouponStrategy::class,
CheckoutSessionLocatorRegistryInitiated::class => RegisterWooCommerceCheckoutSessionLocator::class,
Ready::class => RegisterCreditCheckoutFilter::class,
];
}
public function getEventBindings(): array
{
$autoApply = fn() => new CreditAutoApplyRequested(get_current_user_id(), WooCommerceCreditCouponStrategy::getId());
$discounts = fn($orderId) => $this->container->get(DiscountTransformerService::class)->getDiscountsEvent($orderId);
$reversal = fn($orderId) => $this->container->get(DiscountTransformerService::class)->getDiscountsReversedEvent($orderId);
return [
CreditAutoApplyRequested::class => [
['action' => 'woocommerce_before_checkout_form', 'transformer' => $autoApply],
['action' => 'woocommerce_before_cart', 'transformer' => $autoApply],
// The block cart and checkout actions are bound the same way.
],
OrderDiscountsDetected::class => [
['action' => 'woocommerce_order_status_completed', 'transformer' => $discounts],
['action' => 'woocommerce_order_status_processing', 'transformer' => $discounts],
],
OrderDiscountsReversed::class => [
['action' => 'woocommerce_order_status_refunded', 'transformer' => $reversal],
['action' => 'woocommerce_order_status_cancelled', 'transformer' => $reversal],
],
];
}
public function load(): void
{
// Step 5: stamp the session's hold token on the new order.
$stampHoldToken = function ($order): void {
$locator = $this->container->get(WooCommerceCheckoutSessionLocator::class);
$token = $locator->peekToken();
if ($token !== null) {
$locator->stampOrder((int) $order->get_id(), $token);
}
};
add_action('woocommerce_checkout_order_created', $stampHoldToken, 10, 1);
add_action('woocommerce_store_api_checkout_order_processed', $stampHoldToken, 10, 1);
}
}
The Ready listener hooks the filter from step 3. It leaves admin, cron, and REST requests alone, because there the current user isn’t the shopper:
public function handle(Event $event): void
{
add_filter('woocommerce_coupon_get_amount', [$this, 'filterCouponAmount'], 10, 2);
}
public function filterCouponAmount($amount, $coupon)
{
if (is_admin() || !function_exists('WC') || WC() === null || WC()->cart === null) {
return $amount;
}
$token = $this->locator->getOrCreateToken();
$excludeReference = $token !== null
? HoldService::referenceFor(WooCommerceCheckoutSessionLocator::getId(), $token)
: null;
return $this->checkoutService->getFilteredAmount($amount, strtoupper($coupon->get_code()), get_current_user_id(), $excludeReference);
}
The discount transformer from step 6 reads the token back when it builds the event:
return new OrderDiscountsDetected(
$customerId,
'WooCommerce order #' . $orderId,
$discounts,
$this->locator->getTokenForOrder($orderId)
);
See OrderDiscountsDetected and OrderDiscountsReversed for their payloads, and Store Credit Events for the ledger events that follow.
For the full lifecycle of a tracked sale — from hook to conversion to payout — see the Architecture Overview. For complete event payload documentation, listener details, and the execution order across all event types, see the Events Reference.