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_Product
class is the Subscription extensions counterpart to the WC_Product
class. It is used to extend the WC_Product
class provide an API for accessing details of a subscription product type.
WC_Subscriptions_Product::get_price_string
↑ Torna in cimaUsage
↑ Torna in cima<?php WC_Subscriptions_Product::get_price_string( $product ) ?>
Parameters
↑ Torna in cima- $product
- (mixed) (required) A
WC_Product
object or product ID which will be checked to see if it is of the subscription type.Default: None
Return Values
↑ Torna in cima- (string)
- This string representation of a subscription price including period, duration and sign-up fee, if set.
WC_Subscriptions_Product::get_price
↑ Torna in cimaUsage
↑ Torna in cima<?php WC_Subscriptions_Product::get_price( $product ) ?>
Parameters
↑ Torna in cima- $product
- (mixed) (required) A
WC_Product
object or product ID.Default: None
Return Values
↑ Torna in cima- (mixed)
- The price charged per period for the subscription, or an empty string if the product is not a subscription.
WC_Subscriptions_Product::get_period
↑ Torna in cimaUsage
↑ Torna in cima<?php WC_Subscriptions_Product::get_period( $product ) ?>
Parameters
↑ Torna in cima- $product
- (mixed) (required) A
WC_Product
object or product ID.Default: None
Return Values
↑ Torna in cima- (string)
- A string representation of the period, either Day, Week, Month or Year, or an empty string if product is not a subscription.
WC_Subscriptions_Product::get_length
↑ Torna in cimaUsage
↑ Torna in cima<?php WC_Subscriptions_Product::get_length( $product ) ?>
Parameters
↑ Torna in cima- $product
- (mixed) (required) A
WC_Product
object or product ID.Default: None
Return Values
↑ Torna in cima- (int)
- An integer representing the length of the subscription, or 0 if the product is not a subscription or the subscription continues for perpetuity.
WC_Subscriptions_Product::get_expiration_date
↑ Torna in cima$order_date
if specified, or the current date/time.
Usage
↑ Torna in cima<?php WC_Subscriptions_Product::get_expiration_date( $product_id, $order_date ) ?>
Parameters
↑ Torna in cima- $product
- (int) (required) The ID of the product to determine the expiration date for.Default: None
- $order_date
- (string) (optional) A MYSQL formatted date/time string from which to calculate the expiration date. Defaults to use today’s date/time.Default: Empty (today’s date)
Return Values
↑ Torna in cima- (mixed)
- If the product has a duration, the return is the MYSQL formatted date/time of its expiration from
$order_date
. If no expiration is set, the return is 0.