Paypal | Site Banner Q4 2024

Added by Latoya

Product Icon

WooCommerce Subscriptions

Let customers subscribe to your products or services and pay on a weekly, monthly or annual basis.

Create option to prevent coupons from applying to subscription products/services

We already discount a monthly subscription for a product (similar to Amazon), so I would like to disable all coupons from working on subscriptions. This could be a check box in the subscription settings. In other words, the customer already saves 20% on the product when subscribing, I don’t want to compound the savings by allows a coupon code to take off another 15%

Author

Current Status

Open

Last updated: January 30, 2020

4 comments

Log in to comment on this feature request.

  1. skbypassmobile says:

    Here below are 2 code versions:

    1). For subscription products using “All products for subscription” add on (code is commented):

    add_filter( ‘woocommerce_coupon_is_valid’, ‘disable_coupons_for_subscription_products’, 10, 3 );
    function disable_coupons_for_subscription_products( $is_valid, $coupon, $discount ){
    // Loop through cart items
    foreach ( WC()->cart->get_cart() as $cart_item ) {
    // Check for subscription products using “All products for subscription” add on
    if ( isset($cart_item[‘wcsatt_data’][‘active_subscription_scheme’])
    && ! empty($cart_item[‘wcsatt_data’][‘active_subscription_scheme’]) ) {
    $is_valid = false; // Subscription product found: Make coupons “not valid”
    break; // Stop and exit from the loop
    }
    }
    return $is_valid;
    }

    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):

    add_filter( ‘woocommerce_coupon_is_valid’, ‘disable_coupons_for_subscription_products’, 10, 3 );
    function disable_coupons_for_subscription_products( $is_valid, $coupon, $discount ){
    // Loop through cart items
    foreach ( WC()->cart->get_cart() as $cart_item ) {
    // Check for subscription products
    if( in_array( $cart_item[‘data’]->get_type(), array(‘subscription’, ‘subscription_variation’) ) ) {
    $is_valid = false; // Subscription product found: Make coupons “not valid”
    break; // Stop and exit from the loop
    }
    }
    return $is_valid;
    }
    Code goes in function.php file of your active child theme (or active theme).

    This Tested and works.

  2. designerniknet says:

    The below code is not working now since it is 2years back code. I think you need to change code for latest woocommerce files.

  3. Alec Tremaine says:

    You can try:

    /******************************************
    disable copun code for subscription product
    *******************************************/
    add_filter( ‘woocommerce_coupon_is_valid’, ‘disable_coupons_for_subscription_products’, 10, 3 );
    function disable_coupons_for_subscription_products( $is_valid, $coupon, $discount ){
    // Loop through cart items
    foreach ( WC()->cart->get_cart() as $cart_item ) {
    // Check for subscription products
    if( in_array( $cart_item[‘data’]->get_type(), array(‘subscription’, ‘subscription_variation’) ) ) {
    $is_valid = false; // Subscription product found: Make coupons “not valid”
    break; // Stop and exit from the loop
    }
    }
    return $is_valid;
    }

    add_filter( ‘woocommerce_coupon_is_valid_for_product’, ‘sw_wc_apfs_disable_on_susbcription’, 10, 4 );
    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;
    }

  4. damienrr says:

    Yes 100%

    This is a given

Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.