Order mail to to a second custom field email address

  • Posts: 1
  • Thank you received: 0
15 hours 51 minutes ago #372491

-- HikaShop version -- : HikaShop Business 6.5.0
-- Joomla version -- : 5.4.6
-- PHP version -- : 8.2.30
-- Browser(s) name and version -- : Firefox 152.0.4

Hi,
I need to find a solution where my customers have the possiblity to add another email address in the shipping address.
Most probably this can be done via the custom fields via a new field which will be displayed in the shipping address aera.
But how to ensure that the order confirmation and the PDF invoice will be sent to this email address, too.

Thanks,
Thomas

Please Log in or Create an account to join the conversation.

  • Posts: 85834
  • Thank you received: 14092
  • MODERATOR
6 hours 39 minutes ago #372497

Hi Thomas,

There is no built-in option to route the order emails to an address typed into a custom field, but it only takes a couple of steps.

1) Create the field
In System > Custom fields, add a new field with the Table set to "Address" and a column name of your choice (for example extra_email). Use the "Text" type and, if you want it validated, add an email regex in the field options. It will then appear in the billing/shipping address form on the checkout.

2) Copy the order emails to that address
The order confirmation and the invoice both go out through HikaShop's emails, and the mail object accepts a cc_email (or bcc_email) that is read when the email is sent. So in System > Emails, edit the "Order creation notification" email and paste this at the very top of the HTML body:

<?php
$extra = trim(@$data->cart->shipping_address->extra_email);
if(!empty($extra))
	$mail->cc_email = empty($mail->cc_email) ? $extra : $mail->cc_email.','.$extra;
?>

Replace extra_email with the column name you gave the field (and shipping_address with billing_address if you put the field on the billing address). Use $mail->bcc_email instead of cc_email if you would rather the extra address stays hidden from the customer.

The PDF invoice is attached to the "Order status notification" email (depending on your invoice settings), so add the same three lines to that email too if you want the invoice copied to the field address as well.

Please Log in or Create an account to join the conversation.

Time to create page: 0.072 seconds
Powered by Kunena Forum