In WooCommerce, we have 2 payments methods, cash on delivery and credit card online.
I have the following problem in Checkout page:
The payment processor requires the email address from the customer, and it's mandatory.
Then we have made the billing email field mandatory. But that makes a big drop in the conversion rate.
So what I would like for the "email" field is:
If the customer doesn't enter his email address, then we should autopopulate the field or the data sent to the payment processor with a generic replacement email like "[email protected]".
And if the customer enters his email address, then everything will go through.
Instead, there is a much more effective way: When the order is placed, on order creation, just before the payment, if the billing email is empty and the selected payment method is not COD, we set a temporary generated email address replacement as billing email.
Then, just after the payment, we remove this email replacement.
This temporary email replacement is generated from the customer complete name (or if there is no name, we generate an alphabetical random string) and from a domain name defined in the first function. This way, the payment gateway can't detect that the email is a fake.
The code:
Code goes in functions.php file of your child theme (or in a plugin). It should work.
If needed, here is the code to make the billing email field optional: