Drupal Commerce: Automatically email customers when their order status changes

Mon, 10/20/2014 - 11:43 -- admin

I'm going to show you how to set up a Rule within Drupal Commerce that will tell the system to send an email to a customer when their order status has been changed.  For this to work you will need the following modules:

  1. Drupal Commerce (obviously)
  2. Rules
  3. PHP filter

Once you've enabled these modules, let's navigate to Configuration -> Workflow -> Rules.  Click on the "Add a new rule" link in the top left, and create a Rule with the following parameters:

Events

  • After updating an existing commerce order

Conditions

  • Execute custom PHP code
    • if("[commerce-order:status]" == "completed" && "[commerce-order-unchanged:status]" != "[commerce-order:status]") {
      return TRUE;
      }
      else {
      return FALSE;
      }
    • The above php code will make it so that the customer will only get an email notification if the order status is changed to complete.  This will prevent the customer getting an email every time the order is saved (if the status is already set to complete).

Actions

  • Send mail
    • To value: [commerce-order:mail]
    • Subject value: [site:name] Order Status Updated | [commerce-order:status-title]
    • Message value: The status of your order from [site:name] has been updated to [commerce-order:status-title].
      You may view your order by clicking this link: [commerce-order:customer-url]
    • Leave the From value blank to use the site-wide configured address

That's it!  Save the Rule, and you're all set.  Customers will receive an email with their order status once it's changed (and they won't receive multiple emails if an admin makes changes to an order after it has been completed).