Discussions

Send email when order status is changed to complete

Hello, I would like to know if it is possible to send an email to the customer when their order status is changed from pending to complete.

It would be nice to inform the customer when their order is shipped.

Posted: Sep 1, 2011

Comments

spypolo on September 28, 2011

Create a rule with event After updating an existing commerce order
Create action system send mail to order:email (use patterns)
Add condition

Execute custom PHP code

put this code inside

if([commerce-order:status] == 'completed') return TRUE;
else return FALSE;

HenrikBak on September 29, 2011

I changed the condition a bit to suit my needs. Now the customer only gets an email notification if the order status is changed to complete.

if("[commerce-order:status]" == "completed" && "[commerce-order-unchanged:status]" != "[commerce-order:status]") {
return TRUE;
}
else {
return FALSE;
}

chernoff on August 9, 2013

Or just

return ("[commerce-order:status]" == "completed" && "[commerce-order-unchanged:status]" != "[commerce-order:status]");

Kris Rower on June 30, 2014

Hi

I know this thread was created while agot and not sure how much has changed but I am having troubles finding
"Execute custom PHP code" option ?

Info Drupal 7.27
Info Install profile Commerce Kickstart (commerce_kickstart-7.x-2.14)

All components look reasonable up to date ?

Kevin Goodwin on September 2, 2014

Hi Kris,

I'm not sure if you're still having problems with this but I thought that it could be useful to someone else even if you've found out how to do it.

In order to see the "Execute custom PHP code" in the Condition select box you first need to enable the core module "PHP filter" - go to Site settings/Modules (the address will be yoursite/admin/modules) find the module, enable it and save it. The next time you add a condition you will see the "Execute custom PHP code option" under "PHP" in the list.

I hope this helps.

lance on April 28, 2012

I am pretty sure this can also be done by adding the condition:
Data Comparison:
Parameter: Data to compare: [commerce-order:status], Data value: Completed

But, this does still send the email every time the order is saved. To get around this and to add a bit of flexibility for the user, I added a couple of custom fields.

1. field_send_com (Values = N/A, Tracking Number and Message) This field controls if the message actually gets sent, as well as which message to send.
2. field_order_com (this is a text area to send a custom message to the customer)

Next I created a rule for sending the tracking number, and a rule for sending messages.

Event: After updating an existing commerce order

Condition:
Entity has field
Parameter: Entity: [commerce-order], Field: field_send_com

Data comparison
Parameter: Data to compare: [commerce-order:field-send..., Data value: Message

Action:
Send mail
Parameter: To: [commerce-order:mail

The detail of the message can be edited in the message body, can be tokenized etc.

I did the same thing for the tracking number.

Mark P on December 5, 2012

Serious thanks to all on this thread. Spent 4 hours on this last night and then found this today and fixed it up in 5 minutes. Awesome indeed and www.balancebikes.ca appreciates it. Now to get the email after XX days from order sorted.