Subscriptions Management Function Reference

This documentation is written for WooCommerce developers who want to extend or integrate with the WooCommerce Subscriptions plugin. To follow this documentation, you will need an advanced understanding of PHP and WordPress development.

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. If you need to extend WooCommerce Subscriptions and are not a developer, you can find a developer in the WooExperts directory.

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.

activate_subscriptions_for_order() ↑ Back to top

Activates 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 top

Marks all subscriptions linked to an order as cancelled. This function is called automatically from the 'woocommerce_order_status_cancelled' & 'woocommerce_order_status_refunded' hooks, which are triggered when an order’s status is changed to cancelled or refunded respectively.

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 top

Loops 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 top

Loops 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 top

Marks 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 top

When 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 top

Takes 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 top

Takes 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.

WooCommerce - the most customizable eCommerce platform for building your online business.

Back to the top