Different Email To Customer Depending on Order

  • Posts: 170
  • Thank you received: 26
  • Hikashop Business
2 months 3 days ago #372514

-- HikaShop version -- : 6.5.0 [2605281459]
-- Joomla version -- : 6.1.1
-- PHP version -- : 8.4.22

  • We are selling physical products and as well a digital product.
  • All orders require registration
  • We are using HikaShop Tags to hide content from those who haven't paid for the digital items
  • Now looking to send, in the order confirmation email, to anyone purchasing the digital item or both physical/digital a different email confirmation to those who only purchased the physical products. We are looking to include the link to the "hidden" menu item for them to access a login form redirecting them to the "hidden" page
Possible?

Last edit: 1 month 3 weeks ago by yerg55.

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

  • Posts: 86105
  • Thank you received: 14205
  • MODERATOR
2 months 2 days ago #372522

Hi,

Yes, this is possible. Your order confirmation email is a PHP template, and inside it you have the full list of the products that were purchased, so you can show an extra block (your login / hidden menu link) only when the order contains the digital item, and hide it for orders that are physical only.

In your HikaShop backend go to System > Emails and open the email your customers receive: the "Order creation notification", and/or the "Order status notification" if you would rather reveal the access only once the order is confirmed and paid. Whatever you save there is kept as an update safe override, so a HikaShop update will not overwrite it.

At the spot in the body where you want the link to appear, add this block and set your digital product id(s):

<?php
$digitalProductIds = array(12, 34); // put your digital product id(s) here
$hasDigital = false;
foreach($data->cart->products as $item) {
    if(in_array($item->product_id, $digitalProductIds)) {
        $hasDigital = true;
        break;
    }
}
if($hasDigital) {
    echo '<p><a href="'.HIKASHOP_LIVE.'index.php?Itemid=123">Access your content here</a></p>';
}
?>

Replace 12, 34 with the id(s) of your digital product(s) (you see them in the ID column of the Products listing), and Itemid=123 with the id of your hidden menu item. Customers who bought only physical products will not see the block; anyone who bought the digital item, alone or together with physical products, will get the link.

If you have many digital products and would rather not maintain a list of ids, you can rearrange the code to use a custom product field, or something else based on how you characterize digital products in your shop.

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

  • Posts: 170
  • Thank you received: 26
  • Hikashop Business
1 month 3 weeks ago #372610

Thanks Nicolas

That's all functioning correctly
Emails coming through as expected

I'll post another Item to keep this one focused for others

The following user(s) said Thank You: nicolas

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

  • Posts: 170
  • Thank you received: 26
  • Hikashop Business
1 week 2 days ago #373204

Not sure why but what worked now fails.

The details in the email template don't appear at all.
The email received is perfect but not this
Updates changed anything?

<?php
$digitalProductIds = array(21); // put your digital product id(s) here
$hasDigital = false;
foreach($data->cart->products as $item) {
    if(in_array($item->product_id, $digitalProductIds)) {
        $hasDigital = true;
        break;
    }
}
if($hasDigital) {
    echo '<p><a href="'.HIKASHOP_LIVE.'/10-videos-and-recipes">Access your Recipes and Videos Here</a></p>';
}
?>

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

  • Posts: 86105
  • Thank you received: 14205
  • MODERATOR
1 week 1 day ago #373207

Hi,

Nothing changed on that side in the recent versions: the HTML section of the order creation notification is still plain PHP, and I've just run your exact code on a 6.6.0 test site, the link comes out in the email as expected.

So it's more likely one of these two:

1. The code is no longer in the email. Go to System > Emails, open "Order creation notification" and check the HTML section. Changing the "template" setting of the email, or clicking the restore/reset button, drops your customization back to the default file.

2. The product id doesn't match anymore. If product 21 has variants, the order line stores the id of the variant that was bought, not 21, so the test never matches. This version handles both:

<?php
$digitalProductIds = array(21);
$hasDigital = false;
foreach($data->cart->products as $item) {
	$ids = array((int)$item->product_id);
	$p = @$productClass->all_products[$item->product_id];
	if(!empty($p->product_parent_id))
		$ids[] = (int)$p->product_parent_id;
	if(array_intersect($ids, $digitalProductIds)) {
		$hasDigital = true;
		break;
	}
}
if($hasDigital) {
	echo '<p><a href="'.HIKASHOP_LIVE.'10-videos-and-recipes">Access your Recipes and Videos Here</a></p>';
}
?>

Note that I also removed the slash after HIKASHOP_LIVE, which already ends with one.

To see which ids the email actually gets, add this line temporarily just before the "if($hasDigital)" and place a test order:
echo '<p>ids: '.implode(',', array_map(function($i){ return $i->product_id; }, $data->cart->products)).'</p>';

Could you also confirm the HikaShop version you're now running? It's displayed at the bottom right of your HikaShop backend.

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

  • Posts: 170
  • Thank you received: 26
  • Hikashop Business
1 week 2 hours ago #373262

Updated the code as provided including the echo.
Nothing achieved at all
:(


HikaShop Business 6.6.0 [2608311657]

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

  • Posts: 86105
  • Thank you received: 14205
  • MODERATOR
6 days 14 hours ago #373271

Hi,

I looked into it again today, and tried to reproduce the problem on my end, but the custom code works fine in all my tests with HikaShop 6.6.0.
The problem is elsewhere.
There is some information you didn't provide (or missed) about the situation. For example, if you're looking at another email than the one you modified. Or if you have a specific setup with products I didn't thought about.
I guess the best would be for me to directly look in your backend in order to better understand the situation.
Could you provide a backend access via our contact form ?
www.hikashop.com/support/contact-us.html

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

Time to create page: 0.062 seconds
Powered by Kunena Forum