With WooCommerce I am using WooCommerce Subscriptions plugin. I have mainly Variable Subscription products and some few simple Subscription products.
I am using woocommerce_dropdown_variation_attribute_options_args
filter hook, to update dropdown attribute values on my Variable Subscription products.
For Simple Subscriptions products I would like to add some conditions to allow or deny access to the product page.
So my question is: Which hook could I use to check if a product is a simple subscription, to allow or deny access to the product?
Any help/suggestion will be highly appreciated.
2
Answers
You can use
is_subscription()
ofWC_Subscriptions_Product
. You need to pass$product
object in is_subscription() function as parameter. Check the below code.Update
Use
woocommerce_product_is_visible
filter hook for remove the product from product catalog. check below code.You can check product type on the
WC_Product
object for simple subscription like:or
And here below is an example usage that will avoid access to simple subscription product pages, redirecting customer to main shop page and displaying an error notice:
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
Notes:
To target variable subscription product type use the slug
variable-subscription
.To target a variation subscription, the product type slug is:
subscription_variation
.