Developer hooks
Add these to your theme's functions.php or a small plugin. Every hook starts with edit_orders_for_woocommerce_; the tables leave the prefix out. Each hook has a docblock with its arguments where it fires.
The hold (1.4.0)
| Hook | Type | Arguments | Use |
|---|---|---|---|
should_hold | filter | bool $hold, WC_Order $order | Whether a paid order waits as Open for changes |
hold_started | action | WC_Order $order, int $release_at | An order started waiting |
hold_released | action | WC_Order $order, string $reason | It moved to Processing. Reasons: window_end, customer_closed, shipped, staff, setting_off, deactivated, sweep. |
The time for changes
| Hook | Type | Arguments | Use |
|---|---|---|---|
window_end | filter | int $end, WC_Order $order, int $start | When customer changes end (a timestamp). The countdown, badge and release follow it. Since 1.4.0. |
window_max_seconds | filter | int $seconds | The longest window any order can have. Raise it with window_end, so the Orders screen view finds those orders. Since 1.4.0. |
customer_actions | filter | string[] $actions | The customer actions offered |
customer_can | filter | true|WP_Error $result, WC_Order $order, string $action, string $actor | Final say on a customer action |
order_excluded | filter | bool $excluded, WC_Order $order | Leave an order out of customer changes |
is_shipped | filter | bool $shipped, WC_Order $order | Whether an order counts as shipped |
tracking_meta_keys | filter | string[] $keys | Order meta keys that mean a tracking number was added |
window_closed | action | WC_Order $order | The customer said "All good" |
Customer actions and the panel (1.4.0)
| Hook | Type | Arguments | Use |
|---|---|---|---|
customer_changes | filter | array|null $changes, string $action, WC_Order $order, array $data, string $actor | Turn your own customer action into changes that go through the same preview, confirmation and apply |
customer_action | filter | array|null $result, string $action, WC_Order $order, array $data, string $actor | Carry out an action that isn't a change, such as accepting an offer |
customer_change_intercept | filter | array|null $result, WC_Order $order, array $changes, Settlement_Plan $plan, string $actor | Stop a confirmed change before it is applied, for example to send it for approval |
panel_args | filter | array|null $args, WC_Order $order, string $key | The panel's data. Also asked with null when there is nothing to show. |
panel_actions | action | WC_Order $order, array $actions, string $order_key, array $args | Print more actions, before Cancel |
panel_state | action | array $state, WC_Order $order, string $order_key | Print a state the panel doesn't know, such as an offer |
customer_preview | filter | array $preview, Settlement_Plan $plan, WC_Order $order, string $action | What the customer's preview shows |
preview_after | action | array $preview, WC_Order $order, array $state | At the end of the customer's preview |
balance_redirect | filter | string $url, WC_Order $balance, WC_Order $order, string $actor, array $data | Where the customer goes to pay the difference |
customer_changed | action | WC_Order $order, array $data | A customer changed their order |
Changes and settlement
| Hook | Type | Arguments | Use |
|---|---|---|---|
normalise_change | filter | array|string $result, array $change | Accept a change type of your own. Since 1.4.0. |
plan_change | action | Settlement_Plan $plan, WC_Order $order, array $change | Plan that change type. Since 1.4.0. |
settlement_plan | filter | Settlement_Plan $plan, WC_Order $order, Change_Set $change_set | Adjust a plan before it is previewed or applied |
can_edit | filter | true|WP_Error $result, WC_Order $order, string $action, string $actor | Final say on whether an order can be edited |
can_change_item | filter | true|WP_Error $result, WC_Order $order, WC_Order_Item_Product $item, array $change, string $actor | Final say on a line. Since 1.4.0. |
before_apply | action | WC_Order $order, Settlement_Plan $plan, string $actor, array $args | Before a change is applied or sent for payment. $args since 1.4.0. |
after_apply | action | WC_Order $order, array $result, string $actor, array $args | After it |
plan_run | action | WC_Order $order, Settlement_Plan $plan, WC_Order|null $balance, array $result | Once the money moved and the order was saved, also after a balance order is paid. Since 1.4.0. |
refund_handler | filter | null|array|WP_Error $result, WC_Order $order, array $lines, float $amount, string $reason, string $context, bool $customer_email | Make a refund yourself, for example as store credit. $context is edit, cancel or cancel_balance. Since 1.4.0. |
balance_paid | action | WC_Order $balance, WC_Order $order, array|WP_Error $result | A balance order was paid and its change applied |
manual_refund_needed | action | WC_Order $order, string $amount, int $refund_id, string $gateway_error, string $reason | A refund has to be made by hand |
free_shipping_available | filter | bool $available, WC_Order $order, WC_Shipping_Free_Shipping $method | Whether free shipping applies after an address change |
pay_on_delivery_gateways | filter | string[] $gateways | Payment methods paid on delivery (default cod) |
is_authorization_only | filter | bool $uncaptured, WC_Order $order | Whether a payment is authorized but not captured |
The plan (Edit_Orders_For_WooCommerce_Settlement_Plan) has methods to change it from plan_change or settlement_plan (since 1.4.0): add_refund_line(), set_refund_line(), remove_refund_line(), add_balance_item(), set_balance_item(), add_description(), add_error(), set_extra() and get_extra(). Extra data is saved with the plan and is part of the fingerprint that checks a confirmed change against its preview.
An address change can carry only a shipping_method (a rate ID such as flat_rate:3): the shipping is re-rated and settled like any address change (since 1.4.0).
Cancellations
| Hook | Type | Arguments | Use |
|---|---|---|---|
cancel_intercept | filter | array|null $state, WC_Order $order, array $data, string $actor, string $reason | Show something else instead of cancelling, such as an offer. Since 1.4.0. |
cancel_request_details | filter | array $details, WC_Order $order, array $data, string $actor | Keep more with a request. Since 1.4.0. |
cancel_form_fields | action | WC_Order $order, string $order_key, array $args | Print more fields in the cancel form. Since 1.4.0. |
cancel_refund | filter | array $refund, WC_Order $order, string $actor, string $reason | What a cancellation refunds: lines, amount and fee (a cancellation fee). Since 1.4.0. |
execute_cancel | filter | null|array|WP_Error $result, WC_Order $order, string $actor, string $reason, array $request | Carry out a cancellation yourself, for example a partial one. Since 1.4.0. |
cancel_requested | action | WC_Order $order, string $reason | A customer asked to cancel |
cancelled | action | WC_Order $order, string $actor, string $reason, array $result | An order was cancelled through the plugin |
cancel_declined | action | WC_Order $order, string $message | You declined a request |
request_summary | filter | string $summary, WC_Order $order, array $request | The text of a request in the queue. Since 1.4.0. |
activity_requests | filter | array[] $rows | Add requests of your own type to the queue. Since 1.4.0. |
activity_requests_heading | filter | array $heading (title, description) | Rename the queue when it holds more than cancellations. Since 1.4.0. |
activity_decide | filter | null|true|WP_Error $result, WC_Order $order, string $type, string $decision, string $message | Answer a request of your own type. Since 1.4.0. |
The editor and emails
| Hook | Type | Arguments | Use |
|---|---|---|---|
admin_preview_after | action | WC_Order $order, Settlement_Plan $plan | Print more in your preview, before Apply. Fields here are posted with the change. Since 1.4.0. |
admin_apply_args | filter | array $args, WC_Order $order, array $posted | Options passed on to before_apply. Since 1.4.0. |
admin_address_tab | action | WC_Order $order | Print more fields in the editor's Address tab. Since 1.4.0. |
email_data | filter | array $data, string $email_id, WC_Order $order | The data an email is built from. Since 1.4.0. |
email_after_summary | action | WC_Order $order, array $data, bool $plain_text, WC_Email $email | Print more in each email, before the order details. Since 1.4.0. |
The Edit Orders page (1.4.0)
| Hook | Type | Arguments | Use |
|---|---|---|---|
page_tabs | filter | array[] $tabs | Add a tab: key, label, capability, count. Print it on the action edit_orders_for_woocommerce_page_tab_{key}. |
settings_sections | filter | array[] $nav | Section links on the Settings tab: id, icon, label |
settings_after_sections | action | Print more sections inside the settings form | |
settings_save | action | array $post | Save your fields from the same form |
page_links | filter | string[] $links | The page's links: docs, support, changes, review and any you add |
Settings and logging
| Hook | Type | Arguments | Use |
|---|---|---|---|
setting | filter | mixed $value, string $key | A setting's value |
debug_log | filter | bool $enabled | Turn the debug log on or off from code |
refund_transaction_meta_keys | filter | string[] $keys, WC_Order_Refund $refund | Refund meta keys where a gateway keeps its refund ID, for the log |
Example
Never hold orders shipped by local pickup:
add_filter( 'edit_orders_for_woocommerce_should_hold', function ( $hold, $order ) {
foreach ( $order->get_shipping_methods() as $method ) {
if ( 'local_pickup' === $method->get_method_id() ) {
return false;
}
}
return $hold;
}, 10, 2 );