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()

Activates all the subscriptions linked to an order.

Usage

<?php WC_Subscriptions_Manager::activate_subscriptions_for_order( $order ) ?>

Parameters

$order
(mixed) (required) A WC_Order object or ID of the order for which subscription payments should be marked against. Default: None

Return Values

(void)
This function does not return a value.

cancel_subscriptions_for_order()

Marks 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

<?php WC_Subscriptions_Manager::cancel_subscriptions_for_order( $order ) ?>

Parameters

$order
(mixed) (required) A WC_Order object or ID of the order for which subscription payments should be marked against. Default: None

Return Values

(void)
This function does not return a value.

process_subscription_payments_on_order()

Loops over all subscriptions linked to an order and processes payments on those subscriptions.

Usage

<?php WC_Subscriptions_Manager::process_subscription_payments_on_order( $order ) ?>

Parameters

$order
(mixed) (required) A WC_Order object or ID of the order for which subscription payments should be marked against. Default: None

Return Values

(void)
This function does not return a value.

process_subscription_payment_failure_on_order()

Loops over all subscriptions linked to an order and processes failed payments on those subscriptions.

Usage

<?php WC_Subscriptions_Manager::process_subscription_payment_failure_on_order( $order ) ?>

Parameters

$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

(void)
This function does not return a value.

expire_subscriptions_for_order()

Marks all the subscriptions in an order as expired.

Usage

<?php WC_Subscriptions_Manager::expire_subscriptions_for_order( $order ) ?>

Parameters

$order
(mixed) (required) A WC_Order object or ID of the order for which subscription payments should be marked against. Default: None

Return Values

(void)
This function does not return a value.

failed_subscription_sign_ups_for_order()

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

<?php WC_Subscriptions_Manager::failed_subscription_sign_ups_for_order( $order ) ?>

Parameters

$order
(mixed) (required) A WC_Order object or ID of the order for which subscriptions should be marked as failed. Default: None

Return Values

(void)
This function does not return a value.

cancel_users_subscriptions()

Takes a user ID and cancels any subscriptions that user has in the store.

Usage

<?php WC_Subscriptions_Manager::cancel_users_subscriptions( $user_id ) ?>

Parameters

$user_id
(int) (required) The id of the user whose subscription is to be cancelled. Default: None

Return Values

(void)
This function does not return a value.

cancel_users_subscriptions_for_network()

Takes a user ID and cancels any subscriptions that user has in all stores on a multisite network.

Usage

<?php WC_Subscriptions_Manager::cancel_users_subscriptions_for_network( $user_id ) ?>

Parameters

$user_id
(int) (required) The id of the user whose subscription should be cancelled. Default: None

Return Values

(void)
This function does not return a value.
Was this article helpful?
Dislike 0
Views: 11