apply_filters() slices away needed arguments

Two inherent problems with your script as posted. I’m not certain this will solve your problem, but it’s too big to address in the comments.

First, you need to use add_action(), not add_filter(). That by itself is not a huge deal because add_action() is just a wrapper for add_filter(), but you should still use the correct one.

The other problem may be your passed arguments.

I know that, as a matter of fact, three arguments are passed in the
line I quoted above (namely a null, the refund object and the refund
id),

Actually, the way you have it, you’re not passing three arguments, you’re only passing one. But your function as written is expecting three.

Your add_action() uses the required $tag and $function_to_add values, but leaves off the optional $priority and $accepted_args. The default of $accepted_args is “1”, so anytime you’re passing more than a single value with add_action() or add_filter(), you must define the $accepted_args value.

Try it as follows, noting the final value of “3” – that’s the $accepted_args value that tells it to pass more than 1 argument:

add_action('woocommerce_admin_order_item_values', 'test_refund_id', 10, 3 );
function test_refund_id($nullvar, $refund, $refund_id) {
    if ( !empty($refund->refunded_by) ){
        echo '<td>Refund ID: '.$refund_id.'</td>';  
    }
}

Leave a Comment