Making custom order actions work with the “Trigger Order Action” action

The following documentation is written for developers. To follow this documentation, you will need an advanced understanding of PHP and WordPress development.

WooCommerce order actions can be found in the WooCommerce edit order screen and different plugins, or custom code, can register their own order actions that will appear in the select box.

AutomateWoo includes an action called Trigger Order Action that can run an order action from a workflow.

When creating custom order actions to work with AutomateWoo it’s important to load your code in more than the WordPress admin context. This is because AutomateWoo workflows do not only run in the admin context. There are a couple of solutions available to make a custom order action work with AutomateWoo.

  1. Load the order action code for all requests (e.g. remove any is_admin() conditionals around your code). This works but isn’t very efficient.
  2. The code can be optimized by only loading before the Trigger Order Action action runs (in addition to when you were normally loading it). Be sure to prevent, any logic from running multiple times since multiple actions and workflows can run in the same request. A code example can be found below.