1
votes

I am receiving Warnings when trying to use some arguments in a filter hook.

WARNING: MISSING ARGUMENT 2 FOR UPDATE_SALE() IN C:\WAMP\WWW\FRANK\WP-CONTENT\THEMES\TWENTYTHIRTEEN\FUNCTIONS.PHP ON LINE 688

WARNING: MISSING ARGUMENT 3 FOR UPDATE_SALE() IN C:\WAMP\WWW\FRANK\WP-CONTENT\THEMES\TWENTYTHIRTEEN\FUNCTIONS.PHP ON LINE 688

Here is the signature of the filter I am trying to hook into

echo apply_filters(
            'woocommerce_sale_flash', 
            '<span class="onsale">'.__( 'Sale!', 'woocommerce' ).'</span>', 
            $post, 
            $product);

Here is my custom filter action

function update_sale( $content, $post, $product ) {
    $content = '<span class="onsale">'.__( '25% Off!', 'woocommerce' ).'</span>';
    return $content;
}
add_filter('woocommerce_sale_flash', 'update_sale');

When I include the additional arguments $post, and $product in my function declaration I receive the Warnings above. I thought that $post and $product would give me access to the term data.

So what am I missing here?

thanks

1

1 Answers

1
votes

The WordPress add_filter function will call your update_sale function with the default of only one argument. http://codex.wordpress.org/Function_Reference/add_filter Also in these functions, it's usually easier to grab the post object as a global variable. You might do the same for your product var. However as presented the function doesn't even use these variables so you could probably omit them. [Edit: OP states that when the 4th argument is set in the calling function, the global variables are available without explicitly calling them.]

You could try:

function update_sale($content = '', $post = NULL, $product = NULL){
  global $post;
  // now you can access the post object here if you need to.
  $content = '<span class="onsale">'.__( '25% Off!', 'woocommerce' ).'</span>';
  return $content;
}
add_filter('woocommerce_sale_flash', 'update_sale', 10, 3);

The fourth argument for add_filter tells WordPress that your update_sale function accepts three arguments.