WooSubscriptionsBridge
\Benecaster\Bridge\Bridges\WooSubscriptionsBridge
The built-in bridge for WooCommerce Subscriptions. Slug: woo-subscriptions. Detection: class_exists('WC_Subscriptions'). Tier resolution calls wcs_get_users_subscriptions() and iterates line items against the show’s tier mapping. on_subscription_changed() is a documented no-op. A plan switch is not a cancellation: WooCommerce Subscriptions swaps the product on the same subscription without changing its status, and the bridge hears it on woocommerce_subscription_item_switched as an activation of the new product’s tier. The token stays active and keeps its feed URL, the tier moves, and benecaster_subscription_tier_moved fires — never benecaster_subscription_tier_changed.
Implements BridgeInterface and BridgeWritable, and uses ManualMembershipUnsupportedTrait — create_manual_membership() always throws. The full method contract is documented once on BridgeInterface and BridgeWritable; the table below covers only what this implementation does differently.
Constructor Dependencies
| Type | Description |
|---|---|
TierMapRepository |
Resolves WooCommerce product IDs to Benecaster internal tier slugs, scoped per show. |
Methods
| Method | Visibility | Since | Description |
|---|---|---|---|
get_plugin_slug(): string |
Public | — | Returns 'woo-subscriptions'. |
get_user_tier( int $user_id, int $show_id ): ?string |
Public | — | Iterates the user's active subscriptions from wcs_get_users_subscriptions(), then each subscription's line items, and returns the tier slug of the first product mapped to $show_id. |
get_all_user_tiers( int $user_id, int $show_id ): array |
Public | — | Same iteration as get_user_tier(), but collects every matching tier slug — a subscriber with two active subscriptions mapped to the same show gets both. |
is_user_active( int $user_id, int $show_id ): bool |
Public | — | true when get_user_tier() returns non-null. |
get_all_tiers( int $show_id ): array |
Public | — | Returns every published subscription and variable-subscription product from wc_get_products() as a candidate tier ({id, name, price}). $show_id is accepted for interface compatibility but unused — WooCommerce products are site-wide. |
on_subscription_activated( callable $callback ): void |
Public | — | Registers on four status-transition hooks: pending_to_active (source 'new'), cancelled_to_active and on-hold_to_active (source 'resubscribe'), and pending-cancel_to_active (source 'resumed' — a scheduled cancellation undone before it took effect, the one case where access was never actually interrupted). Also on woocommerce_subscription_item_switched (source 'new'): a plan switch on the same subscription, reported as the new product's tier. A switch onto a product mapped to no tier does nothing. |
on_subscription_cancelled( callable $callback ): void |
Public | — | Registers on woocommerce_subscription_status_cancelled (SubscriptionEndReason::CANCELLED) and _expired (::EXPIRED — a fixed-length subscription reaching its end), which are separate WooCommerce Subscriptions statuses. |
on_subscription_changed( callable $callback ): void |
Public | — | No-op, deliberately. Its callback ends in benecaster_subscription_tier_changed, which sends the Tier Change email; a plan switch is heard in on_subscription_activated() instead, which moves the tier with no email. In the usual single-product case a switch neither cancels the old subscription nor creates a new one. |
on_subscription_renewed( callable $callback ): void |
Public | — | Registers on woocommerce_subscription_renewal_payment_complete, fired after a renewal order completes. |
on_payment_failed( callable $callback ): void |
Public | — | Registers on woocommerce_subscription_status_on-hold, fired when a subscription is suspended after a failed payment. |
on_tier_saved( callable $callback ): void |
Public | — | Registers on woocommerce_update_product, filtered to the subscription and variable-subscription product types, and calls $callback with {id, name, price} — price is the lowest variant price for a variable subscription. |
register_admin_hooks(): void |
Public | — | Not defined on this bridge — WooCommerce Subscriptions has no tier-mapping metabox equivalent to the other three external bridges. Plugin.php checks method_exists() before calling it, so this is a silent, deliberate omission rather than an oversight. |
can_import(): bool |
Public | — | true when wcs_create_subscription() and wc_get_product() both exist. |
create_member( string $email, int $user_id, int $tier_id, array $meta = [] ): bool |
Public | — | Creates a subscription via wcs_create_subscription() with no parent order (order_id = 0), adds the product as a zero-total line item, and activates it. $meta['billing_interval'] ('monthly' | 'annual', default 'monthly') sets the billing period. No charge is issued and no order appears in the store's order history. |
supports_tier( int $tier_id ): bool |
Public | — | true when $tier_id resolves to a product of type subscription, variable-subscription, or subscription_variation. |
create_manual_membership( int $user_id, int $show_id, string $tier_slug, ?string $expiry_at ): array |
Public | — | Inherited from ManualMembershipUnsupportedTrait — always throws BadMethodCallException. |