Subscription Order & Cart Function Reference

The Subscription Order & Cart Function Reference guide 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 that 3rd party code can use to interact with WooCommerce Subscriptions.

For a more comprehensive source of information in how WooCommerce Subscriptions interacts with WooCommerce orders and the cart, refer to the following source files:

  • wcs-order-functions.php
  • wcs-cart-functions.php
  • class-wc-subscriptions-order.php
  • class-wc-subscriptions-cart.php

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.

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.

Usage

↑ Back to top
<?php wcs_order_contains_subscription( $order, $order_type ) ?>

Parameters

↑ Back to top

$order (mixed) (required) The WC_Order object or ID of the order which should be checked. Default: None

$order_type (array|string) (optional) Can include ‘parent’, ‘renewal’, ‘resubscribe’ and/or ‘switch’. Defaults to ‘parent’.

Return Values

↑ Back to top

(bool) True if the order contains a subscription, otherwise false.

wcs_get_subscriptions_for_order()

↑ Back to top

Get all of the subscriptions (i.e. WC_Subscription objects or a given order.

Usage

↑ Back to top
<?php wcs_get_subscriptions_for_order( $order_id, $args ) ?>

Parameters

↑ Back to top

$order_id (mixed) (required) The WC_Order object or ID of the order to get the corresponding subscriptions for.

$args (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.

Return Values

↑ Back to top

(array) Set of subscriptions in an array with the form ID => WC_Subscription form.

Cart Functions

↑ Back to top

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

WC_Subscriptions_Cart::cart_contains_subscription

↑ Back to top

Checks the cart to see if it contains a subscription product.

Usage

↑ Back to top
<?php WC_Subscriptions_Cart::cart_contains_subscription() ?>

Return Values

↑ Back to top

(bool) True if the cart contains a subscription product, otherwise false.

Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.