1. Documentação /
  2. Introduction to Woo Subscriptions /
  3. Introduction to Subscriptions Developer Documentation /
  4. Subscription Function & Property Reference /
  5. Subscription Product Function Reference

Subscription Product 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_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

↑ Voltar Para o Topo
Returns a string representing the details of the subscription. For example “$20 per Month for 3 Months with a $10 sign-up fee”.

Usage

↑ Voltar Para o Topo
<?php WC_Subscriptions_Product::get_price_string( $product ) ?>

Parameters

↑ Voltar Para o Topo
$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

↑ Voltar Para o Topo
(string)
This string representation of a subscription price including period, duration and sign-up fee, if set.

WC_Subscriptions_Product::get_price

↑ Voltar Para o Topo
Returns the price per period for a product if it is a subscription.

Usage

↑ Voltar Para o Topo
<?php WC_Subscriptions_Product::get_price( $product ) ?>

Parameters

↑ Voltar Para o Topo
$product
(mixed) (required) A WC_Product object or product ID.Default: None

Return Values

↑ Voltar Para o Topo
(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

↑ Voltar Para o Topo
Returns the subscription period for a product, if it’s a subscription.

Usage

↑ Voltar Para o Topo
<?php WC_Subscriptions_Product::get_period( $product ) ?>

Parameters

↑ Voltar Para o Topo
$product
(mixed) (required) A WC_Product object or product ID.Default: None

Return Values

↑ Voltar Para o Topo
(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

↑ Voltar Para o Topo
Returns the length of the subscription for a product, if it is a subscription. Length is represented by an integer for the number of periods payment will recur. For example, for a subscription lasting 6 months, this function would return 6.

Usage

↑ Voltar Para o Topo
<?php WC_Subscriptions_Product::get_length( $product ) ?>

Parameters

↑ Voltar Para o Topo
$product
(mixed) (required) A WC_Product object or product ID.Default: None

Return Values

↑ Voltar Para o Topo
(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

↑ Voltar Para o Topo
Takes a subscription product’s ID and returns the date on which the subscription product will expire, based on the subscription’s length and calculated from either the $order_date if specified, or the current date/time.

Usage

↑ Voltar Para o Topo
<?php WC_Subscriptions_Product::get_expiration_date( $product_id, $order_date ) ?>

Parameters

↑ Voltar Para o Topo
$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

↑ Voltar Para o Topo
(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.