I am trying to disable coupon codes for my WooCommerce Subscriptions that I have set up through the "all products for subscription" add on. I've tried the snippet below but it's not targeting subscription products added through the "all products for subscription" plugin. I could be in the wrong direction completely.
I have a test product here
Below is my code attempt:
function sw_wc_apfs_disable_on_susbcription( $is_valid, $product, $instance, $values ) {
if ( ! empty( $values[ ‘wcsatt_data’][ ‘active_subscription_scheme’ ] ) ) {
$is_valid = false;
}
return $is_valid;
}
It doesn't work… Any help is appreciated.
Your code is a bit incomplete, as the hook is missing, from your code. Also there are some mistakes in your code.
There is only 3 arguments
woocommerce_coupon_is_valid
hook, so you need to loop through cart items instead.Here below are 2 code versions:
1). For subscription products using "All products for subscription" add on (code is commented):
Code goes in function.php file of your active child theme (or active theme). It should works.
2). For normal subscription products (code is commented):
Code goes in function.php file of your active child theme (or active theme). Tested and works.