Using WooCoomerce along with WooCommerce Bookings plugin. In their API Reference, there’s a listed filter for modifying booking cost: woocommerce_bookings_calculated_booking_cost
. To cut it short, here’s how it’s applied in the code:
return apply_filters( 'woocommerce_bookings_calculated_booking_cost', $booking_cost, $product, $data );
Now, I’ve added following code, to try and change the price:
function foobar_price_changer( $booking_cost, $product, $data ) {
return $booking_cost;
}
add_filter( 'woocommerce_bookings_calculated_booking_cost', 'foobar_price_changer' );
Now, when I use that code, it throws an error in my logs:
PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function sbnb_modify_wc_bookings_price(), 1 passed in /mywppath/wp-includes/class-wp-hook.php on line 290 and exactly 3 expected in /mywppath/wp-content/themes/enfold-child/functions.php:155
As far as I read it, 3 arguments are passed to the add_filter callbacks, but in my case it only passes one. What could be the issue here?
2
Answers
Give it a try this way
If you don’t specify the $accepted_args or the fourth parameter when calling add_filter function, it passes by default only one parameter to your callback function. So whenever there are more than one argument to pass to the callback function, you have to specify the number of the expected arguments.
From wp-includes/plugin.php: