Skip to main content

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)​

HookTypeArgumentsUse
should_holdfilterbool $hold, WC_Order $orderWhether a paid order waits as Open for changes
hold_startedactionWC_Order $order, int $release_atAn order started waiting
hold_releasedactionWC_Order $order, string $reasonIt moved to Processing. Reasons: window_end, customer_closed, shipped, staff, setting_off, deactivated, sweep.

The time for changes​

HookTypeArgumentsUse
window_endfilterint $end, WC_Order $order, int $startWhen customer changes end (a timestamp). The countdown, badge and release follow it. Since 1.4.0.
window_max_secondsfilterint $secondsThe longest window any order can have. Raise it with window_end, so the Orders screen view finds those orders. Since 1.4.0.
customer_actionsfilterstring[] $actionsThe customer actions offered
customer_canfiltertrue|WP_Error $result, WC_Order $order, string $action, string $actorFinal say on a customer action
order_excludedfilterbool $excluded, WC_Order $orderLeave an order out of customer changes
is_shippedfilterbool $shipped, WC_Order $orderWhether an order counts as shipped
tracking_meta_keysfilterstring[] $keysOrder meta keys that mean a tracking number was added
window_closedactionWC_Order $orderThe customer said "All good"

Customer actions and the panel (1.4.0)​

HookTypeArgumentsUse
customer_changesfilterarray|null $changes, string $action, WC_Order $order, array $data, string $actorTurn your own customer action into changes that go through the same preview, confirmation and apply
customer_actionfilterarray|null $result, string $action, WC_Order $order, array $data, string $actorCarry out an action that isn't a change, such as accepting an offer
customer_change_interceptfilterarray|null $result, WC_Order $order, array $changes, Settlement_Plan $plan, string $actorStop a confirmed change before it is applied, for example to send it for approval
panel_argsfilterarray|null $args, WC_Order $order, string $keyThe panel's data. Also asked with null when there is nothing to show.
panel_actionsactionWC_Order $order, array $actions, string $order_key, array $argsPrint more actions, before Cancel
panel_stateactionarray $state, WC_Order $order, string $order_keyPrint a state the panel doesn't know, such as an offer
customer_previewfilterarray $preview, Settlement_Plan $plan, WC_Order $order, string $actionWhat the customer's preview shows
preview_afteractionarray $preview, WC_Order $order, array $stateAt the end of the customer's preview
balance_redirectfilterstring $url, WC_Order $balance, WC_Order $order, string $actor, array $dataWhere the customer goes to pay the difference
customer_changedactionWC_Order $order, array $dataA customer changed their order

Changes and settlement​

HookTypeArgumentsUse
normalise_changefilterarray|string $result, array $changeAccept a change type of your own. Since 1.4.0.
plan_changeactionSettlement_Plan $plan, WC_Order $order, array $changePlan that change type. Since 1.4.0.
settlement_planfilterSettlement_Plan $plan, WC_Order $order, Change_Set $change_setAdjust a plan before it is previewed or applied
can_editfiltertrue|WP_Error $result, WC_Order $order, string $action, string $actorFinal say on whether an order can be edited
can_change_itemfiltertrue|WP_Error $result, WC_Order $order, WC_Order_Item_Product $item, array $change, string $actorFinal say on a line. Since 1.4.0.
before_applyactionWC_Order $order, Settlement_Plan $plan, string $actor, array $argsBefore a change is applied or sent for payment. $args since 1.4.0.
after_applyactionWC_Order $order, array $result, string $actor, array $argsAfter it
plan_runactionWC_Order $order, Settlement_Plan $plan, WC_Order|null $balance, array $resultOnce the money moved and the order was saved, also after a balance order is paid. Since 1.4.0.
refund_handlerfilternull|array|WP_Error $result, WC_Order $order, array $lines, float $amount, string $reason, string $context, bool $customer_emailMake a refund yourself, for example as store credit. $context is edit, cancel or cancel_balance. Since 1.4.0.
balance_paidactionWC_Order $balance, WC_Order $order, array|WP_Error $resultA balance order was paid and its change applied
manual_refund_neededactionWC_Order $order, string $amount, int $refund_id, string $gateway_error, string $reasonA refund has to be made by hand
free_shipping_availablefilterbool $available, WC_Order $order, WC_Shipping_Free_Shipping $methodWhether free shipping applies after an address change
pay_on_delivery_gatewaysfilterstring[] $gatewaysPayment methods paid on delivery (default cod)
is_authorization_onlyfilterbool $uncaptured, WC_Order $orderWhether 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​

HookTypeArgumentsUse
cancel_interceptfilterarray|null $state, WC_Order $order, array $data, string $actor, string $reasonShow something else instead of cancelling, such as an offer. Since 1.4.0.
cancel_request_detailsfilterarray $details, WC_Order $order, array $data, string $actorKeep more with a request. Since 1.4.0.
cancel_form_fieldsactionWC_Order $order, string $order_key, array $argsPrint more fields in the cancel form. Since 1.4.0.
cancel_refundfilterarray $refund, WC_Order $order, string $actor, string $reasonWhat a cancellation refunds: lines, amount and fee (a cancellation fee). Since 1.4.0.
execute_cancelfilternull|array|WP_Error $result, WC_Order $order, string $actor, string $reason, array $requestCarry out a cancellation yourself, for example a partial one. Since 1.4.0.
cancel_requestedactionWC_Order $order, string $reasonA customer asked to cancel
cancelledactionWC_Order $order, string $actor, string $reason, array $resultAn order was cancelled through the plugin
cancel_declinedactionWC_Order $order, string $messageYou declined a request
request_summaryfilterstring $summary, WC_Order $order, array $requestThe text of a request in the queue. Since 1.4.0.
activity_requestsfilterarray[] $rowsAdd requests of your own type to the queue. Since 1.4.0.
activity_requests_headingfilterarray $heading (title, description)Rename the queue when it holds more than cancellations. Since 1.4.0.
activity_decidefilternull|true|WP_Error $result, WC_Order $order, string $type, string $decision, string $messageAnswer a request of your own type. Since 1.4.0.

The editor and emails​

HookTypeArgumentsUse
admin_preview_afteractionWC_Order $order, Settlement_Plan $planPrint more in your preview, before Apply. Fields here are posted with the change. Since 1.4.0.
admin_apply_argsfilterarray $args, WC_Order $order, array $postedOptions passed on to before_apply. Since 1.4.0.
admin_address_tabactionWC_Order $orderPrint more fields in the editor's Address tab. Since 1.4.0.
email_datafilterarray $data, string $email_id, WC_Order $orderThe data an email is built from. Since 1.4.0.
email_after_summaryactionWC_Order $order, array $data, bool $plain_text, WC_Email $emailPrint more in each email, before the order details. Since 1.4.0.

The Edit Orders page (1.4.0)​

HookTypeArgumentsUse
page_tabsfilterarray[] $tabsAdd a tab: key, label, capability, count. Print it on the action edit_orders_for_woocommerce_page_tab_{key}.
settings_sectionsfilterarray[] $navSection links on the Settings tab: id, icon, label
settings_after_sectionsactionPrint more sections inside the settings form
settings_saveactionarray $postSave your fields from the same form
page_linksfilterstring[] $linksThe page's links: docs, support, changes, review and any you add

Settings and logging​

HookTypeArgumentsUse
settingfiltermixed $value, string $keyA setting's value
debug_logfilterbool $enabledTurn the debug log on or off from code
refund_transaction_meta_keysfilterstring[] $keys, WC_Order_Refund $refundRefund 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 );