Hello and good day to you ??
Is your plugin capable to force the coupon only if specific products are being checked out?
Thank you and kind regards,
Sascha
Hi,
I really need help to apply the force coupon to a specific category or product. I have been trying to work with the following code I found in Stack Overflow by adding it to the functions.php in current theme folder, but it brings the whole site down:
// Force Coupon codes for Woocommerce
add_action(‘woocommerce_check_cart_items’, ‘mandatory_coupon_code’);
function mandatory_coupon_code()
{
// set Here your categories IDs, slugs or names
$categories = array(18,19,87);
$found = false;
// Loop through cart items
foreach ( WC()->cart->get_cart() as $cart_item )
if( has_term( $categories, ‘product_cat’, $cart_item[‘product_id’] ) ){
// Product category found in cart items
$found = true;
// Exit from loop
break;
}
}
$coupons = WC()->cart->get_applied_coupons();
// The Notice is displayed for that product categories when no mandatory coupon has been entered
if( count( $coupons ) > 0 && $found )
wc_add_notice( __( ‘A coupon code is mandatory for this product.’, ‘woocommerce’ ), ‘error’ );
I am running the latest version of both WordPress and Woocommerce.
Please could you help me?
Thank you Mohammed for this great plugin, but I am wondering if it is up to date? as it is not updated for 2 years now
Thanks
]]>Great little plugin, very helpful! I was just wondering if there is an option somewhere to select specific products to require coupons, or if there is a hook I could throw into my functions file? So far in testing I’m seeing that ALL products now require coupon code?
]]>