Force a coupon to be applied before checkout in WooCommerce

Force a coupon to be applied before checkout in WooCommerce on your child site.

Snippet Type

Execute on Child Sites

Snippet

function mandatory_coupon_code() {
    $applied_coupons = WC()->cart->get_applied_coupons();

    if ( empty ( $applied_coupons ) ) {
        // Not found: display an error notice
        wc_add_notice( __( 'Add coupon before checkout.', 'woocommerce' ), 'error' );   
    }
}
add_action( 'woocommerce_check_cart_items', 'mandatory_coupon_code', 10, 0 );
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.