Hi @cryothic
I had a look at the docs and I can’t see anything that allows you to change the logic or cancel an abandoned cart email. Your best option would be to disable the built-in mechanism and write your own using the CartAbandonedNotification event.
Here’s the solution AI came back with:
You’re right that EmailSendingNotification is a dead end here — it doesn’t give you a way to cancel the send, so you can’t filter from there.
The cleaner approach is to handle the CartAbandonedNotification event instead and do the sending yourself, so you’re in full control of who gets an email. The trick is that this works in two parts:
- Clear the Abandoned Cart Email Template in Store Settings > Cart Settings. With no template set, Commerce stops sending its own email, but detection keeps running and the notification still fires. This is what lets you take over the send.
- Handle
CartAbandonedNotification, loop the order IDs, resolve the member, check your flag, and only send to those who haven’t opted out.
The registration has to go inside the AddUmbracoCommerce(...) callback in a composer — that’s a common gotcha; registered on the bare IUmbracoBuilder it compiles but never fires:
public class CommerceComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.AddUmbracoCommerce(commerceBuilder =>
{
commerceBuilder
.WithNotificationEvent<CartAbandonedNotification>()
.RegisterHandler<AbandonedCartHandler>();
});
}
}
And the handler, with the member-flag check:
public class AbandonedCartHandler : NotificationEventHandlerBase<CartAbandonedNotification>
{
private readonly IServiceProvider _serviceProvider;
public AbandonedCartHandler(IServiceProvider serviceProvider)
=> _serviceProvider = serviceProvider;
public override void Handle(CartAbandonedNotification evt)
{
using var scope = _serviceProvider.CreateScope();
var orderService = scope.ServiceProvider.GetRequiredService<IOrderService>();
var memberService = scope.ServiceProvider.GetRequiredService<IMemberService>();
foreach (var orderId in evt.OrderIds)
{
var order = orderService.GetOrder(orderId);
if (order?.CustomerInfo is null) continue;
// however you've stored the member reference on the order at checkout
if (!Guid.TryParse(order.CustomerInfo.CustomerReference, out var memberKey))
continue; // guest checkout -> skip
var member = memberService.GetByKey(memberKey);
if (member is null) continue;
// opt-out style: skip if they've ticked the box
if (member.GetValue<bool>("disallowAbandonedCartEmail")) continue;
// (or opt-in: if (!member.GetValue<bool>("allowAbandonedCartEmail")) continue;)
// send your email here
}
}
}
Two things to check on your side:
- How the member is attached to the order at checkout. I’ve used
CustomerInfo.CustomerReferenceabove, but check what you actually set when the member places the order — it might be a custom order property or an email match againstIMemberService. That lookup is the bit to get right. - One honest caveat: I’m confident clearing the template stops the native send (the docs note that with no template, no email goes out but notifications/webhooks still fire), but I haven’t seen it confirmed whether the notification fires alongside the built-in send or instead of it. So test it — clear the template, trigger an abandoned cart, and make sure no duplicate native email goes out. If it does, we can dig further.
The one trade-off is you lose the built-in conversion-rate widget tracking, since that’s tied to Commerce sending the email itself. If you rely on that, worth factoring in.
Hope that helps!
Justin