Hello,
The cleanest way to do this is a small custom HikaShop plugin (group "hikashop") that listens to the onBeforeMailSend event. That event fires for every email HikaShop sends out, gives you the full order context, and lets you add a CC or BCC on the fly without modifying any email template. The existing confirmation emails stay exactly as they are; you only ADD extra recipients on the orders that match your locations.
Plugin file (extra_recipients.php):
<?php
defined('_JEXEC') or die('Restricted access');
class plgHikashopExtra_recipients extends JPlugin {
public function onBeforeMailSend(&$mail, &$mailer) {
// Only act on order creation notifications. This skips status-change
// emails, account-creation emails, password resets, etc.
if (empty($mail->mail_name)) return;
if (!in_array($mail->mail_name, array(
'order_creation_notification',
'order_admin_notification'))) {
return;
}
// The order object is in $mail->data for order-related emails.
$order = isset($mail->data) ? $mail->data : null;
if (empty($order) || empty($order->shipping_address)) return;
// Match on the shipping address. address_state usually holds the
// state name or code, but you can also test address_city or
// address_post_code if your "location" lives there.
$state = isset($order->shipping_address->address_state)
? trim($order->shipping_address->address_state) : '';
$city = isset($order->shipping_address->address_city)
? trim($order->shipping_address->address_city) : '';
$locations = array('Essex', 'Norfolk');
$match = false;
foreach ($locations as $loc) {
if (strcasecmp($state, $loc) === 0 ||
strcasecmp($city, $loc) === 0) {
$match = true;
break;
}
}
if (!$match) return;
// Add the extra recipient. Replace with the Newport News address.
// Use addBCC if you don't want the customer to see it in the
// headers; use addCC if you do.
$mailer->addBCC('newport.news@example.com', 'Newport News');
}
}The matching plugin manifest (extra_recipients.xml) is a standard Joomla plugin descriptor with <extension type="plugin" group="hikashop">. Zip the two files together and install it from Extensions > Manage > Install, then enable the plugin in Extensions > Plugins.
A few notes:
If your "location" really lives in a different field, like a postcode prefix, the country code, a custom address field, etc you need to replace the $state / $city test with whatever you need. Every column of the address row is available on $order->shipping_address.
If you want different recipients per location (Essex -> one address, Norfolk -> another), turn the locations array into a map and pick the recipient per match instead of using a single addBCC at the end.
For the customer's copy (mail_name == 'order_creation_notification') vs the merchant's copy ('order_admin_notification'), you can decide which one(s) you want the extra recipient added to by tightening the in_array() above.