In WooCommerce, actions are events that occur during specific stages of an order, such as when an order is placed, paid, or completed. You can use actions to trigger custom functions or perform specific tasks, such as sending an email notification or updating stock levels. To use actions in WooCommerce, you need to:

  1. Create a custom plugin or add custom code to your theme’s functions.php file.
  2. Use the add_action function to hook into a specific action in WooCommerce.
  3. Define the function that you want to be executed when the action is triggered.

For example, the following code adds a custom function to the woocommerce_order_status_completed action, which is triggered when an order is marked as completed in the admin panel:


function custom_function_on_order_completion( $order_id ) {
    // Perform custom actions here
}
add_action( 'woocommerce_order_status_completed', 'custom_function_on_order_completion' );

This code adds the custom_function_on_order_completion function to the woocommerce_order_status_completed action, so it will be executed every time an order is completed in the admin panel. The $order_id parameter is passed to the function, so you can access information about the completed order.