WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm customizing a Woocommerce Wordpress site.

In the Woocommerce product class (class-wc-product.php) the get_price function applies a filter as follows:

function get_price() {
    return apply_filters('woocommerce_get_price', $this->price, $this);

In my functions.php I want to add a filter as follows:

add_filter('woocommerce_get_price', 'custom_price');

function custom_price($price, $product) {

When I call this I get the following PHP warning:

Warning: Missing argument 2 for custom_price()

Why is the second argument missing? Is $this not sent to the filter call?

share|improve this question
Maybe apply_filters('woocommerce_get_price', … ); is called somewhere else without the second argument? Did you search for such a case? – toscho Nov 12 '12 at 15:10
It's called only once as far as I can see – benedict_w Nov 12 '12 at 15:12
up vote 9 down vote accepted

It's missing the second argument because you didn't tell WordPress you wanted it with your add_filter call. By default, actions and filters only get one argument. Try this:

add_filter('woocommerce_get_price', 'custom_price', 10, 2);

function custom_price($price, $product) {
share|improve this answer
Good answer Chris, exactly why I love this site. I learn something new every day. – Stephen Nov 12 '12 at 16:10

The warning is a result of the second argument in your function custom_price(). The filter provides only one variable on the call and I can't remember if this is the product/post ID or the price. The code docs indicate that it returns a string so I'd presume it's the price.

You can hopefully find the documentation at http://wcdocs.woothemes.com/apidocs/index.html

If you need the product at this point you'll have to use:

function custom_price( $price ) {

    global $product;


If all else fails simply echo $price to see if you can tell if it's a product ID or a price. Then adjust your code accordingly.

share|improve this answer
Thanks for your insights @chrisguitarguy's anwser seems to have done the trick for me. – benedict_w Nov 12 '12 at 15:52
Yeah, it's certainly a more elegant solution. – Stephen Nov 12 '12 at 16:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.