Skip to content

Hooks & filters

The plugin's public surface is intentionally small: one action for writing entries, and four filters for shaping behavior. Everything is prefixed wc_order_audit_log.

Action: wc_order_audit_log

Write a custom audit note through the plugin's pipeline (prefix applied, no actor suffix — compose your own text):

php
do_action( 'wc_order_audit_log', $order_id, 'Contract #42 attached' );

The message may contain safe HTML such as links. If the plugin is inactive the action is simply a no-op, so calling code needs no class_exists guard (though it may want a fallback if the note is essential).

Filter: wc_order_audit_log_note_prefix

Prefix prepended to every note the plugin writes. Default: '' (no prefix).

php
add_filter( 'wc_order_audit_log_note_prefix', function () {
    return '[Audit] ';
} );

Filter: wc_order_audit_log_ignored_props

Order fields excluded from change logging. Receives the default list and the order being saved:

php
add_filter( 'wc_order_audit_log_ignored_props', function ( $props, $order ) {
    $props[] = 'transaction_id';
    return $props;
}, 10, 2 );

Removing entries from the list works too — for example, dropping 'status' would add a field-diff line for status changes (normally left to WooCommerce's own note plus the plugin's actor note).

Filter: wc_order_audit_log_email_notes

Master switch for the built-in order-email notes. Default true. Return false when another email logger writes richer notes, to avoid duplicates:

php
add_filter( 'wc_order_audit_log_email_notes', '__return_false' );

Filter: wc_order_audit_log_email_note

Adjust the email note text before it is written. Receives the message, order, WooCommerce email ID, and the WC_Email instance:

php
add_filter( 'wc_order_audit_log_email_note', function ( $message, $order, $email_id, $email ) {
    return $message . ' (' . $email_id . ')';
}, 10, 4 );

Integrating a custom email logger

A site that stores full email copies (in a custom post type, for example) can take over email notes entirely while keeping them in the audit trail — disable the built-in notes and write richer ones through the action:

php
// In the email logger, once the copy is stored:
add_filter( 'wc_order_audit_log_email_notes', '__return_false' );

$note = sprintf(
    'Email sent to %s: "%s" <a href="%s">View email</a>',
    esc_html( $recipient ),
    esc_html( $subject ),
    esc_url( $view_url )
);
do_action( 'wc_order_audit_log', $order_id, $note );

The dependency points from the site to the plugin — the plugin never needs to know the site's code exists.

PHP API

Two public methods complement the hooks:

MethodPurpose
WC_Order_Audit_Log::reset_request_state()Clear per-request suppression sets in long-running processes (queue workers, test suites).
WC_Order_Audit_Log::log_email_sent( $return, $email_id, $email )The woocommerce_email_sent handler, callable directly for custom mailers that mimic WC_Email.

Released under the GPL-2.0-or-later License.