There are two new product types in such case: “Simple Subscription” and “Variable Subscription”, with the difference being you can offer multiple billing periods within the same product page (choice between daily, monthly and yearly for example) with the latter.
So, how do we know if a given product ID is a subscription, and also whether it’s a simple or variable one? Here’s the quick solution – enjoy!
You can create a “simple subscription” or a “variable subscription” product thanks to WooCommerce Subscriptions plugin. But how do we know if the product is a subscription from the frontend?
PHP: check if product ID is a subscription
$product = wc_get_product( $product_id );
if ( class_exists( 'WC_Subscriptions_Product' ) && WC_Subscriptions_Product::is_subscription( $product ) ) {
// do something
}
PHP: check if product ID is a Simple subscription
$product = wc_get_product( $product_id );
if ( $product->is_type( 'subscription' ) ) {
// do something
}
PHP: check if product ID is a Variable subscription
$product = wc_get_product( $product_id );
if ( $product->is_type( 'variable-subscription' ) ) {
// do something
}