Website Building » WooCommerce » Where Are WooCommerce Actions Defined?

Where Are WooCommerce Actions Defined?

Last updated on January 14, 2023 @ 7:56 am

WooCommerce actions are defined in the woocommerce_actions filter. This filter is located in /includes/class-wc-query.php. The following is a list of all the default actions that are defined by WooCommerce:

  • order_status_changed – Triggered when an order status is changed.
  • order_created – Triggered when an order is created.
  • before_checkout_form – Triggered before the checkout form is displayed.
  • after_checkout_form – Triggered after the checkout form is displayed.
  • checkout_order_processed – Triggered when an order is processed.
  • checkout_validation, – Triggered during checkout validation.

The woocommerce_actions filter can be used to add, remove, or change the priority of any of these actions. For example, if you want to add a new action called “new_action”, you would use the following code:

 add_filter( 'woocommerce_actions', 'new_action' );
function new_action( $actions ) {
$actions[] = 'new_action'; return $actions; } 

You can also use this filter to remove an action by using the “remove” function. For example, if you want to remove the “order_created” action, you would use the following code:

remove_action( 'woocommerce_actions', 'order_created' );

It’s important to note that when using the woocommerce_actions filter, you should always make sure to use the correct action name. Also, be mindful of the order in which you add or remove actions, as this can affect how your website functions.

PRO TIP: Please be aware that the WooCommerce Actions are defined in the ‘woocommerce_init’ function which is located in the /wc-includes/functions.php file. If you change any of these actions, it is your responsibility to ensure that the functions are correctly defined. Failure to do so may result in your site not functioning correctly.

Additionally, you can also change the priority of an action by using the “add_action” function and specifying the priority level. For example, if you want to change the priority of the “checkout_validation” action to have a higher priority, you would use the following code:

add_action( 'woocommerce_actions', 'checkout_validation', 10 );

This would increase the priority level of the “checkout_validation” action, causing it to be executed before other actions with a lower priority level.

In conclusion, the woocommerce_actions filter is a powerful tool that allows you to customize and extend the functionality of your WooCommerce website. By understanding how to add, remove, and change the priority of actions, you can make your website work exactly the way you want it to.

Morgan Bash

Morgan Bash

Technology enthusiast and Co-Founder of Women Coders SF.