The WC_Subscriptions_Manager
class is responsible for managing the subscription across its lifecycle. This involves updating subscription statuses when certain events occur, like order status changes, preparing renewal orders when a scheduled renewal payment is due and deleting subscriptions when a user’s account is deleted.
For example, subscription activation and cancellation functions are hooked directly to order status changes so payment gateways only need to work with WooCommerce APIs to change the status of an order, and a subscriptions status will change automatically.
You can however call the WC_Subscriptions_Manager
class’s public functions directly if needed. This document provides a reference for some of the functions this class provides that may be useful.
If you are looking for a guide to creating and managing subscription products in a WooCommerce store, please refer to the Store Manager Guide instead.
Note: We are unable to provide support for customizations under our Support Policy. If you need to customize a snippet or extend its functionality, we recommend working with a Woo Agency Partner or finding a WooCommerce developer on Codeable.
activate_subscriptions_for_order()
↑ Back to topActivates all the subscriptions linked to an order.
Usage
↑ Back to top<?php WC_Subscriptions_Manager::activate_subscriptions_for_order( $order ) ?>
Parameters
↑ Back to top$order
(mixed) (required) A WC_Order
object or ID of the order for which subscription payments should be marked against. Default: None
Return Values
↑ Back to top(void)
This function does not return a value.
cancel_subscriptions_for_order()
↑ Back to topMarks all subscriptions linked to an order as cancelled. This function is called automatically from the 'woocommerce_order_status_cancelled'
hook, which is triggered when an order’s status is changed to cancelled.
Usage
↑ Back to top<?php WC_Subscriptions_Manager::cancel_subscriptions_for_order( $order ) ?>
Parameters
↑ Back to top$order
(mixed) (required) A WC_Order
object or ID of the order for which subscription payments should be marked against. Default: None
Return Values
↑ Back to top(void)
This function does not return a value.
process_subscription_payments_on_order()
↑ Back to topLoops over all subscriptions linked to an order and processes payments on those subscriptions.
Usage
↑ Back to top<?php WC_Subscriptions_Manager::process_subscription_payments_on_order( $order ) ?>
Parameters
↑ Back to top$order
(mixed) (required) A WC_Order
object or ID of the order for which subscription payments should be marked against. Default: None
Return Values
↑ Back to top(void)
This function does not return a value.
process_subscription_payment_failure_on_order()
↑ Back to topLoops over all subscriptions linked to an order and processes failed payments on those subscriptions.
Usage
↑ Back to top<?php WC_Subscriptions_Manager::process_subscription_payment_failure_on_order( $order ) ?>
Parameters
↑ Back to top$order
(mixed) (required) A WC_Order
object or ID of the order for which subscription payment failures should be marked against. Default: None
Return Values
↑ Back to top(void)
This function does not return a value.
expire_subscriptions_for_order()
↑ Back to topMarks all the subscriptions in an order as expired.
Usage
↑ Back to top<?php WC_Subscriptions_Manager::expire_subscriptions_for_order( $order ) ?>
Parameters
↑ Back to top$order
(mixed) (required) A WC_Order
object or ID of the order for which subscription payments should be marked against. Default: None
Return Values
↑ Back to top(void)
This function does not return a value.
failed_subscription_sign_ups_for_order()
↑ Back to topWhen a payment/subscription sign up fails during the payment processing step, this function will process failed payment for all subscriptions linked to the order. This function is called automatically from the 'woocommerce_order_status_failed'
hook, which is triggered when an order’s status is changed to failed.
Usage
↑ Back to top<?php WC_Subscriptions_Manager::failed_subscription_sign_ups_for_order( $order ) ?>
Parameters
↑ Back to top$order
(mixed) (required) A WC_Order
object or ID of the order for which subscriptions should be marked as failed. Default: None
Return Values
↑ Back to top(void)
This function does not return a value.
cancel_users_subscriptions()
↑ Back to topTakes a user ID and cancels any subscriptions that user has in the store.
Usage
↑ Back to top<?php WC_Subscriptions_Manager::cancel_users_subscriptions( $user_id ) ?>
Parameters
↑ Back to top$user_id
(int) (required) The id of the user whose subscription is to be cancelled. Default: None
Return Values
↑ Back to top(void)
This function does not return a value.
cancel_users_subscriptions_for_network()
↑ Back to topTakes a user ID and cancels any subscriptions that user has in all stores on a multisite network.
Usage
↑ Back to top<?php WC_Subscriptions_Manager::cancel_users_subscriptions_for_network( $user_id ) ?>
Parameters
↑ Back to top$user_id
(int) (required) The id of the user whose subscription should be cancelled. Default: None
Return Values
↑ Back to top(void)
This function does not return a value.