[Skip to main content](#vessel-content)

#   Override notify mail address when certain products are ordered

##

- **[yolknet](/forum/user/12476-yolknet "View yolknet's Profile")**
- [![yolknet's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/12476-yolknet "View yolknet's Profile") Topic Author
- [ Offline](/forum/user/12476-yolknet)

Less More

- Posts: 53
- Thank you received: 3
-
-

5 months 2 weeks ago [\#371920](#371920) by [yolknet](/forum/user/12476-yolknet "View yolknet's Profile")  *[Override notify mail address when certain products are ordered](/forum/27-checkout/910524-override-notify-mail-address-when-certain-products-are-ordered#371920 "In the general Hikashop settings you can set an admin email address that receives the notification when a product is ordered. For certain products I want to use a different email address. Is it possible to override this setting?")* was created by *[yolknet](/forum/user/12476-yolknet "View yolknet's Profile")*

In the general Hikashop settings you can set an admin email address that receives the notification when a product is ordered. For certain products I want to use a different email address. Is it possible to override this setting?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkxMDUyNC1vdmVycmlkZS1ub3RpZnktbWFpbC1hZGRyZXNzLXdoZW4tY2VydGFpbi1wcm9kdWN0cy1hcmUtb3JkZXJlZD90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86323
- Thank you received: 14283
-
-

5 months 2 weeks ago [\#371922](#371922) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Override notify mail address when certain products are ordered](/forum/27-checkout/910524-override-notify-mail-address-when-certain-products-are-ordered#371922 "In the general Hikashop settings you can set an admin email address that receives the notification when a product is ordered. For certain products I want to use a different email address. Is it possible to override this setting?")*

Hi,

The proper way to do it would be via HikaMarket Multivendor:
[ www.hikashop.com/hikamarket-multi-vendor.html](https://www.hikashop.com/hikamarket-multi-vendor.html)
You can configure one vendor per email address, and then select the vendor in each product.
Vendors will then be notified automatically by HikaMarket when an order is made with products linked to them and they'll only see their products in the order.
This is great so that you can have users purchase different products from different vendors in the same order and keep everything tidy.
And the main merchant can still receive his notification of orders with all the products in case this is necessary.

But it is also possible to override the receiver email address dynamically. For that, you want to edit the order admin notification ( sent to the admin when the order is created) and / or the payment notification (sent to the admin when the order is confirmed automatically by a payment plugin) via the menu System&gt;Emails. This will then require custom PHP coding in the preload section at the bottom of the email edit form.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkxMDUyNC1vdmVycmlkZS1ub3RpZnktbWFpbC1hZGRyZXNzLXdoZW4tY2VydGFpbi1wcm9kdWN0cy1hcmUtb3JkZXJlZD90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[yolknet](/forum/user/12476-yolknet "View yolknet's Profile")**
- [![yolknet's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/12476-yolknet "View yolknet's Profile") Topic Author
- [ Offline](/forum/user/12476-yolknet)

Less More

- Posts: 53
- Thank you received: 3
-
-

5 months 2 weeks ago [\#371982](#371982) by [yolknet](/forum/user/12476-yolknet "View yolknet's Profile")  Replied by *[yolknet](/forum/user/12476-yolknet "View yolknet's Profile")* on topic *[Override notify mail address when certain products are ordered](/forum/27-checkout/910524-override-notify-mail-address-when-certain-products-are-ordered#371982 "In the general Hikashop settings you can set an admin email address that receives the notification when a product is ordered. For certain products I want to use a different email address. Is it possible to override this setting?")*

Hello Nicolas,
I found the Order administrator notification email and searched in the preload version, but can't find the variable that holds the to-address. The variable $mail is used for the greeting at the top of the message.
Where in the file can I override the mail address of the receiver?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkxMDUyNC1vdmVycmlkZS1ub3RpZnktbWFpbC1hZGRyZXNzLXdoZW4tY2VydGFpbi1wcm9kdWN0cy1hcmUtb3JkZXJlZD90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86323
- Thank you received: 14283
-
-

5 months 2 weeks ago [\#371985](#371985) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Override notify mail address when certain products are ordered](/forum/27-checkout/910524-override-notify-mail-address-when-certain-products-are-ordered#371985 "In the general Hikashop settings you can set an admin email address that receives the notification when a product is ordered. For certain products I want to use a different email address. Is it possible to override this setting?")*

Hello,

The variable you are looking for is hidden one layer up: inside the preload, the recipient is not on $mail yet, it is built from $data-&gt;customer-&gt;user_email after the preload returns. The order code does, in sequence:

1. $order-&gt;customer-&gt;user_email is replaced with the configured admin notification emails (the "Notification email" setting from Configuration &gt; Emails).
2. Your preload runs with $data = the order (so $data-&gt;customer-&gt;user_email is currently those admin emails).
3. Just after the preload, HikaShop sets $order-&gt;mail-&gt;dst_email = $order-&gt;customer-&gt;user_email and sends.

So in the preload you do not touch $mail-&gt;dst_email (it would be overwritten); you change $data-&gt;customer-&gt;user_email and let HikaShop propagate it.

In HikaShop &gt; System &gt; Emails, edit "Order administrator notification" and paste this in the Preload section at the bottom of the form:
Code:

&lt;?php // Map a product (or its parent product, for variants) to the // recipient email address that should receive the admin notification // when that product is in the order. Replace the example ids and // addresses with yours, or add as many rows as you need. $override_map = array( 42 =&gt; 'sales-team-a@example.com', 99 =&gt; 'sales-team-b@example.com', ); if(!empty($data) &amp;&amp; !empty($data-&gt;cart-&gt;products) &amp;&amp; !empty($data-&gt;customer)) { foreach($data-&gt;cart-&gt;products as $p) { $pid = isset($p-&gt;product_id) ? (int)$p-&gt;product_id : 0; $ppid = isset($p-&gt;product_parent_id) ? (int)$p-&gt;product_parent_id : 0; $to = isset($override_map[$pid]) ? $override_map[$pid] : (($ppid &amp;&amp; isset($override_map[$ppid])) ? $override_map[$ppid] : null); if($to !== null) { // Full replacement of the recipient. If you would rather // ADD to the configured admin emails instead of replacing // them, do: // $current = (array)$data-&gt;customer-&gt;user_email; // $current[] = $to; // $data-&gt;customer-&gt;user_email = $current; $data-&gt;customer-&gt;user_email = $to; break; } } } ?&gt;

A few notes:

- The match looks at both $p-&gt;product_id (so a variant id) and $p-&gt;product_parent_id (the main product), so listing the parent's id in the map is enough to cover all its variants. Add the variant id to the map only if you want a per-variant override.
- If you would rather match by category instead of by product, replace the inner block with a check on the product's categories. The simplest way is to do one DB query in the preload to grab the categories for the order's products and match against a category id whitelist. Happy to provide a snippet for that variant if you want.
- If multiple products in the same order match different recipients and you want all of them to be notified, build an array of addresses across the loop (do not break on the first match) and assign it to $data-&gt;customer-&gt;user_email at the end.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkxMDUyNC1vdmVycmlkZS1ub3RpZnktbWFpbC1hZGRyZXNzLXdoZW4tY2VydGFpbi1wcm9kdWN0cy1hcmUtb3JkZXJlZD90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[yolknet](/forum/user/12476-yolknet "View yolknet's Profile")**
- [![yolknet's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/12476-yolknet "View yolknet's Profile") Topic Author
- [ Offline](/forum/user/12476-yolknet)

Less More

- Posts: 53
- Thank you received: 3
-
-

5 months 2 weeks ago [\#371994](#371994) by [yolknet](/forum/user/12476-yolknet "View yolknet's Profile")  Replied by *[yolknet](/forum/user/12476-yolknet "View yolknet's Profile")* on topic *[Override notify mail address when certain products are ordered](/forum/27-checkout/910524-override-notify-mail-address-when-certain-products-are-ordered#371994 "In the general Hikashop settings you can set an admin email address that receives the notification when a product is ordered. For certain products I want to use a different email address. Is it possible to override this setting?")*

Thank you for the example Nicolas. It makes much more sense now.
If you can make an example based on category 41 that would be much appreciated.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkxMDUyNC1vdmVycmlkZS1ub3RpZnktbWFpbC1hZGRyZXNzLXdoZW4tY2VydGFpbi1wcm9kdWN0cy1hcmUtb3JkZXJlZD90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86323
- Thank you received: 14283
-
-

5 months 2 weeks ago [\#371995](#371995) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Override notify mail address when certain products are ordered](/forum/27-checkout/910524-override-notify-mail-address-when-certain-products-are-ordered#371995 "In the general Hikashop settings you can set an admin email address that receives the notification when a product is ordered. For certain products I want to use a different email address. Is it possible to override this setting?")*

Hello,

Sure, here is the category-based version. Same idea, but instead of matching on the product id we look up the categories of the products in the order and check whether at least one of them is the special category.

Replace the previous preload with this one: Code:

&lt;?php // Map a category id to the recipient email address that should // receive the admin notification when any product in that category // is in the order. Add more rows here if you want to handle several // categories with different recipients. $category_override_map = array( 41 =&gt; 'category-41-team@example.com', ); if(!empty($data) &amp;&amp; !empty($data-&gt;cart-&gt;products) &amp;&amp; !empty($data-&gt;customer)) { // Collect both the variant id and its parent product id, since // categories in HikaShop are typically assigned on the main // product, not on each variant. $product_ids = array(); foreach($data-&gt;cart-&gt;products as $p) { if(!empty($p-&gt;product_id)) $product_ids[(int)$p-&gt;product_id] = (int)$p-&gt;product_id; if(!empty($p-&gt;product_parent_id)) $product_ids[(int)$p-&gt;product_parent_id] = (int)$p-&gt;product_parent_id; } if(!empty($product_ids)) { $db = JFactory::getDBO(); $db-&gt;setQuery( 'SELECT DISTINCT category_id FROM ' . hikashop_table('product_category') . ' WHERE product_id IN (' . implode(',', $product_ids) . ')' ); $order_categories = array_map('intval', (array)$db-&gt;loadColumn()); foreach($category_override_map as $catId =&gt; $to) { if(in_array((int)$catId, $order_categories, true)) { // Full replacement of the recipient. If you would rather ADD // to the configured admin emails instead of replacing them, do: // $current = (array)$data-&gt;customer-&gt;user_email; // $current[] = $to; // $data-&gt;customer-&gt;user_email = $current; $data-&gt;customer-&gt;user_email = $to; break; } } } } ?&gt;

Quick notes:

- The lookup goes through the product_category table, so it picks up every category a product is assigned to, not only the primary one. That way an order containing a product that is in category 41 plus other categories still routes to category-41-team@example.com.
- The "break" means the first matching category in the map wins. If you would rather notify several recipients when an order spans multiple mapped categories, collect them in an array as shown in the comment instead of breaking out.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkxMDUyNC1vdmVycmlkZS1ub3RpZnktbWFpbC1hZGRyZXNzLXdoZW4tY2VydGFpbi1wcm9kdWN0cy1hcmUtb3JkZXJlZD90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[yolknet](/forum/user/12476-yolknet "View yolknet's Profile")**
- [![yolknet's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/12476-yolknet "View yolknet's Profile") Topic Author
- [ Offline](/forum/user/12476-yolknet)

Less More

- Posts: 53
- Thank you received: 3
-
-

5 months 1 week ago [\#372049](#372049) by [yolknet](/forum/user/12476-yolknet "View yolknet's Profile")  Replied by *[yolknet](/forum/user/12476-yolknet "View yolknet's Profile")* on topic *[Override notify mail address when certain products are ordered](/forum/27-checkout/910524-override-notify-mail-address-when-certain-products-are-ordered#372049 "In the general Hikashop settings you can set an admin email address that receives the notification when a product is ordered. For certain products I want to use a different email address. Is it possible to override this setting?")*

Thank you very much for you help Nicolas.
It's in the live webshop now and I will keep an eye on it in the next days.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkxMDUyNC1vdmVycmlkZS1ub3RpZnktbWFpbC1hZGRyZXNzLXdoZW4tY2VydGFpbi1wcm9kdWN0cy1hcmUtb3JkZXJlZD90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[yolknet](/forum/user/12476-yolknet "View yolknet's Profile")**
- [![yolknet's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/12476-yolknet "View yolknet's Profile") Topic Author
- [ Offline](/forum/user/12476-yolknet)

Less More

- Posts: 53
- Thank you received: 3
-
-

3 weeks 4 days ago [\#100000189](#100000189) by [yolknet](/forum/user/12476-yolknet "View yolknet's Profile")  Replied by *[yolknet](/forum/user/12476-yolknet "View yolknet's Profile")* on topic *[Override notify mail address when certain products are ordered](/forum/27-checkout/910524-override-notify-mail-address-when-certain-products-are-ordered#100000189 "In the general Hikashop settings you can set an admin email address that receives the notification when a product is ordered. For certain products I want to use a different email address. Is it possible to override this setting?")*

Hi Nicolas,
There is something not correct in the code you wrote. I have to following lines in the preload section of the order_admin_notification:

// Map a category id to the recipient email address that should
// receive the admin notification when any product in that category
// is in the order. Add more rows here if you want to handle several
// categories with different recipients.
$category_override_map = array(
50 =&gt; 'info@elsva.com',
);

if(!empty($data) &amp;&amp; !empty($data-&gt;cart-&gt;products) &amp;&amp; !empty($data-&gt;customer)) {
// Collect both the variant id and its parent product id, since
// categories in HikaShop are typically assigned on the main
// product, not on each variant.
$product_ids = array();
foreach($data-&gt;cart-&gt;products as $p) {
if(!empty($p-&gt;product_id))
$product_ids[(int)$p-&gt;product_id] = (int)$p-&gt;product_id;
if(!empty($p-&gt;product_parent_id))
$product_ids[(int)$p-&gt;product_parent_id] = (int)$p-&gt;product_parent_id;
}

if(!empty($product_ids)) {
$db = JFactory::getDBO();
$db-&gt;setQuery(
'SELECT DISTINCT category_id FROM ' . hikashop_table('product_category') .
' WHERE product_id IN (' . implode(',', $product_ids) . ')'
);
$order_categories = array_map('intval', (array)$db-&gt;loadColumn());

foreach($category_override_map as $catId =&gt; $to) {
if(in_array((int)$catId, $order_categories, true)) {
// Full replacement of the recipient. If you would rather ADD
// to the configured admin emails instead of replacing them, do:
// $current = (array)$data-&gt;customer-&gt;user_email;
// $current[] = $to;
// $data-&gt;customer-&gt;user_email = $current;
$data-&gt;customer-&gt;user_email = $to;
break;
}
}
}
}

If someone orders a product from category 50 the email isn't send.

Can I also add a second email address to the same category?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkxMDUyNC1vdmVycmlkZS1ub3RpZnktbWFpbC1hZGRyZXNzLXdoZW4tY2VydGFpbi1wcm9kdWN0cy1hcmUtb3JkZXJlZD90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86323
- Thank you received: 14283
-
-

3 weeks 3 days ago [\#100000190](#100000190) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Override notify mail address when certain products are ordered](/forum/27-checkout/910524-override-notify-mail-address-when-certain-products-are-ordered#100000190 "In the general Hikashop settings you can set an admin email address that receives the notification when a product is ordered. For certain products I want to use a different email address. Is it possible to override this setting?")*

The code itself works: I put it in the preload of the "Order admin notification" email on a test shop (HikaShop 6.6.0, Joomla 6) and ordered a product of the mapped category, and the admin notification went to the address of the map instead of the configured one.

It only matches the categories a product is directly assigned to. If category 50 is a parent category and your products are in its subcategories, no product matches, so the notification goes to the usual addresses from the HikaShop configuration and never to the one in the map. I could reproduce exactly that by putting a parent category in the map.

Also make sure the address is between single quotes on both sides, 50 =&gt; 'name@domain.com', with straight quotes (not curly quotes copied from a web page). A syntax error in the preload stops the admin notification for every order.

Attached is admin-notification-by-category.txt, an updated version of the code that handles both points:

- it matches the category and all its subcategories (and, for variants, the categories of their main product),

- each category can have several addresses: 50 =&gt; array('first@example.com', 'second@example.com'),

- with $category_override_replace = true; these addresses replace the configured ones; set it to false to send to these addresses in addition to the configured ones.

In the HikaShop backend, go to System &gt; Emails, edit "Order admin notification", remove your current block from the Preload tab and paste the content of the file at the very end of the Preload tab instead, then change the category id and the addresses in $category_override_map and save. I tested this version on the same test shop: with a parent category in the map and two addresses, both addresses received the notification, and an order without a product of that category still went to the configured address.

If it still does not reach the address after that, please check that the address can receive mail from your site (spam folder, mail server logs); HikaShop hands the mail to Joomla's mailer the same way as for the configured admin address.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkxMDUyNC1vdmVycmlkZS1ub3RpZnktbWFpbC1hZGRyZXNzLXdoZW4tY2VydGFpbi1wcm9kdWN0cy1hcmUtb3JkZXJlZD90bXBsPW1hcmtkb3du) or [Create an account](/register) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.072 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
