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.
This document provides a reference for a few utility functions in the WooCommerce Subscriptions code base relating to orders and the cart.
It is neither exhaustive nor instructive of when to use these functions. It is simply intended as a reference for a few public functions 3rd party code can use to interact with Subscriptions.
For a more comprehensive source of information in how Subscriptions interacts with WooCommerce orders and the cart, refer to the following source files:
wcs_order_contains_subscription() ↑ Back to top
Checks a given order to see if it was used to purchase a
WC_Subscription object via checkout.
<?php wcs_order_contains_subscription( $order, $order_type ) ?>
- (mixed) (required) The
WC_Orderobject or ID of the order which should be checked. Default: None
- (array|string) (optional) Can include ‘parent’, ‘renewal’, ‘resubscribe’ and/or ‘switch’. Defaults to ‘parent’.
Trueif the order contains a subscription, otherwise
wcs_get_subscriptions_for_order() ↑ Back to top
Get all of the subscriptions (i.e.
WC_Subscription objects or a given order.
<?php wcs_get_subscriptions_for_order( $order_id, $args ) ?>
- (mixed) (required) The
WC_Orderobject or ID of the order to get the corresponding subscriptions for.
- (array) (optional) A set of name value pairs to filter the returned value. Refer to the PHP DocBlock on
wcs_get_subscriptions_for_order()for available fitlers.
- Set of subscriptions in an array with the form
ID => WC_Subscriptionform.
Cart Functions ↑ Back to top
WC_Subscriptions_Cart class is mostly dedicated to overloading its
WC_Cart counterpart and does not provide many functions intended to be used as public APIs. However, it does have one important function:
WC_Subscriptions_Cart::cart_contains_subscription ↑ Back to top
Checks the cart to see if it contains a subscription product.
<?php WC_Subscriptions_Cart::cart_contains_subscription() ?>
Trueif the cart contains a subscription product, otherwise