I am running a product as a service in woo-commerce, where we maintain a droop-down list as code for each customer to select own code and get discount. Now the list is going to increase 100+ We are using a simple plugin where we adding droop-down list code set the price multiply with quantity. Now we have plan to bind customer email address to discount code. Note: I am discussing logic then code, using coupon interface to create coupon in admin, then adding a input box to add email and bind with price. all code will be done in function.php file
add_action( 'woocommerce_before_cart' , 'add_coupon_to_email' );
add_action( 'woocommerce_before_checkout_form' , 'add_coupon_to_email' );
function add_coupon_to_email() {
$cart_total = WC()->cart->get_subtotal();
$user_email = Get_wp_user_email // get the customer email from worpdress
$currency_code = get_woocommerce_currency();
if ( $user_email != $Get_wp_user_email ) {
WC()->cart->remove_coupon( 'COUPON' );
} else {
WC()->cart->apply_coupon( 'COUPON' );
}
}