I am trying to provide a specific discounts based on Coupons, which are applied automatically on the Checkout Page.
Now my issue is that I want to limit these coupons for all payment methods except Cash On Delivery. Is there any way I can remove the coupon based on the selection of the payment methods on the checkout page.
Please check the code below which is added the themes function.php to add the coupons.
add_action( 'woocommerce_after_checkout_form', 'apply_matched_coupons' );
function apply_matched_coupons() {
global $woocommerce;
$coupon_code = 'spedisc10'; // your coupon code here
if ( $woocommerce->cart->has_discount( $coupon_code ) ) return;
if ( $woocommerce->cart->total >= 1000) {
$woocommerce->cart->add_discount( $coupon_code );
$woocommerce->show_messages();
}
}
Thanks and regards,
Sandeep