I’m not sure I understand the request. The “To” field is filled in by the purchasing customer. The gift card will be sent to that email address. The only time it is pre-filled is when the user is logged in. Could you explain a little further your use case?
Thread Starter
wpuser
(@slipslide)
I want to sell gift cards for two unrelated businesses. So when Gift Card A sells, I’d like Business A to receive an email notification. Am not quite sure how to do that (apart from opening a marketplace) so thought that rather than the purchasing customer entering an email address, maybe this can be pre-filled by the admin somehow so when Business A’s card sells, Business A’s email address will automatically be entered and they then receive the email when it is purchased.
You could use a hook to carbon-copy (or bcc) the email address of the business owner based upon which gift card product ID was sold. The gift card would still be sent to the recipient and the business owner will get a copy.
1. Download the functions.php from your FTP server at /wp-content/themes/<your theme>/functions.php
2. Keep a backup of functions.php in case there are problems.
3. Edit functions.php and scroll to the very end and add this code.
Note: if the last line is “?>” then put this code *above* that line. Otherwise, this code goes at the very end of the file:
function custom_woocommerce_email_headers( $header, $email_id, $gift_card ) {
// Only for "PW Gift Card" email notification
if( 'pwgc_email' !== $email_id || empty( $gift_card ) ) {
return $header;
}
$carbon_copy = '';
// 123 is the gift card product ID for Business A
if ( $gift_card->product->get_id() == 123 ) {
$carbon_copy = 'businessA@email.com';
}
// 184 is the gift card product ID for Business B
if ( $gift_card->product->get_id() == 184 ) {
$carbon_copy = 'businessB@email.com';;
}
if ( !empty( $carbon_copy ) ) {
$formatted_email = utf8_decode( $carbon_copy );
$header .= "Cc: " . $formatted_email . "\r\n";
}
return $header;
}
add_filter( 'woocommerce_email_headers', 'custom_woocommerce_email_headers', 10, 3 );
4. Save the functions.php file and re-upload it to your server.
Replace functions.php with your backup file if you have any problems.
If you want to “Blind Carbon-Copy” rather than “Carbon-Copy”, change the “Cc” to be “Bcc” in the code above.
Let me know if you have any questions!
Closing this ticket, let me know if you need anything else. Best of luck with your store!