Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
* Plugin Name: All Products for WooCommerce Subscriptions - Disable Coupons When Cart contains products on Subscription
* Plugin URI:
* Description: Use this snippet to prevent coupons from applying in the cart if there is at least one product on Subscription there.
* Version: 1.0
* Author: WooCommerce
* Author URI:
* Developer: Jason Kytros
* Copyright: © 2021 Automattic.
* License: GNU General Public License v3.0
* License URI:
add_filter( 'woocommerce_coupon_is_valid', 'apfs_disable_for_products_on_subscription', 10, 3 );
function apfs_disable_for_products_on_subscription( $is_valid, $coupon, $object ){
$cart_contents = WC()->cart->cart_contents;
foreach ( $cart_contents as $cart_item ) {
if ( ! empty( $cart_item[ 'wcsatt_data'][ 'active_subscription_scheme' ] ) ) {
$is_valid = false;
return $is_valid;
Copy link

Hi, Any idea on how to apply that coupon code is added only to subscribed products and only to the first quantity of each product?? I will really appreciate if someone can help me.

Copy link

This snippet will work but, when applying a coupon manually in a new order using the Dashboard a "Coupon is not valid." error message will appear, any way to fix that?

Copy link

ciitech commented Aug 9, 2022


This code works but when you want to create a manual order form the backend it gives an error when adding a coupon.

Any ideas?



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment