Woocoomerce hooks for order cheatsheet
Certainly, Woocommerce is a powerful tool that provides a wide range of e-commerce robust functions and these core functions use a proper life cycle.
We can extend the e-commerce app using woo-commerce hooks.
The Hooks are actions and filters that help to change the data using the filter hook and add your custom function using the action hook.
Here’s a WooCommerce order hooks cheat sheet that provides some common hooks and their descriptions. WooCommerce is a popular e-commerce plugin for WordPress, and hooks allow you to customize and extend its functionality by executing custom code at specific points in the order processing lifecycle.
woocommerce_new_order:
Description: Triggered when a new order is created.
Example Use Case: Sending notifications or performing custom actions when a new order is placed.
woocommerce_order_status_changed:
Description: Triggered when the order status changes.
Example Use Case: Sending notifications or performing actions based on order status changes (e.g., processing to completed).
woocommerce_order_status_{status}:
Description: Triggered when an order transitions to a specific status.
Example Use Case: Performing actions specific to a particular order status (e.g., on-hold, processing, completed).
woocommerce_order_status_completed:
Description: Triggered when an order is marked as completed.
Example Use Case: Fulfillment, inventory management, or sending follow-up emails.
woocommerce_order_status_processing:
Description: Triggered when an order is marked as processing.
Example Use Case: Inventory updates, order processing, or custom notifications.
woocommerce_order_status_pending:
Description: Triggered when an order is pending payment.
Example Use Case: Handling payment gateways, sending payment reminders.
woocommerce_order_status_cancelled:
Description: Triggered when an order is canceled.
Example Use Case: Restoring inventory, updating records, sending cancellation notifications.
woocommerce_order_status_on-hold:
Description: Triggered when an order is on-hold.
Example Use Case: Sending on-hold notifications.
Please note: Here I added all actions related to the status change you can copy only one that is related to your requirements.
woocommerce_pre_payment_complete:
Description: Executed at the very beginning of payment.
Example Use Case: Applies at the very beginning and doesn’t depend on order status
woocommerce_payment_complete:
Description: Executed when a payment for an order is completed.
Example Use Case: Unlocking access to digital products, sending order completion emails.
woocommerce_order_item_meta_end:
Description: Executed at the end of displaying order item meta data.
Example Use Case: Adding custom information to display alongside order items in emails or on the order page.
These are just a few examples of WooCommerce order hooks. To use them, you’ll need to add custom code to your WordPress theme’s functions.php file or use a custom plugin. Be cautious when working with hooks, as they involve direct manipulation of the WooCommerce order data and can affect your store’s functionality. Always test your custom code thoroughly before deploying it to a live website.
Thanks