Ecommerce Shopify WordPress Discussion

Require coupon code at checkout for WooCommerce

I'm trying to force customers to use any valid coupon code at checkout in my Woo store. The item is free but it's for my restaurant which I'd like the customer to come into the restaurant and allow us to input the coupon code or tell them the code for successful checkout. The category is "Redeem" which is a free coupon category in my WooCommerce store, but I'd like for clients to not redeem them outside of the store, since I have set the use of the coupons once, or purchase of products once per account. I tried using this code but it might be outdated since it doesn't allow to get to checkout page. add_action( 'woocommerce_check_cart_items', 'mandatory_coupon_code' ); function mandatory_coupon_code() { $product_categories = array( 'redeem' ); // Category ID or slug of targeted category $coupon_code = '0001'; // The required coupon code $coupon_applied = in_array( strtolower($coupon_code), WC()->cart->get_applied_coupons() ); // Loop through cart items foreach ( WC()->cart->get_cart() as $cart_item ){ if( has_term( $product_categories, 'product_cat', $cart_item['product_id'] ) && ! $coupon_applied ) { wc_clear_notices(); // Clear all other notices // Avoid checkout displaying an error notice wc_add_notice( sprintf( 'The product"%s" requires a coupon for checkout.', $cart_item['data']->get_name() ), 'error' ); break; // stop the loop } } }
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.