0

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' );
    }
     
}
Ramiz Syed
  • 23
  • 5
  • To get customer email he must be logedin. $user_id = get_current_user_id(); $user_info = get_userdata($user_id); $user_info->user_email . Read more here - https://developer.wordpress.org/reference/functions/get_userdata/ – Snuffy Apr 21 '23 at 14:06

0 Answers0