Last active
August 9, 2022 14:23
-
-
Save somewherewarm-snippets/1cfa3dd57f2348e7515d8517044dd564 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: All Products for WooCommerce Subscriptions - Disable Coupons When Cart contains products on Subscription | |
* Plugin URI: https://woocommerce.com/products/all-products-for-woocommerce-subscriptions/ | |
* 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: https://woocommerce.com/ | |
* Developer: Jason Kytros | |
* | |
* | |
* Copyright: © 2021 Automattic. | |
* License: GNU General Public License v3.0 | |
* License URI: http://www.gnu.org/licenses/gpl-3.0.html | |
*/ | |
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; | |
break; | |
} | |
} | |
return $is_valid; | |
} |
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?
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?
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.