In woocommerce plugin file class-wc-booking-cart-manager.php
there is this code
/**
* Constructor
*/
public function __construct() {
add_filter( 'woocommerce_add_cart_item', array( $this, 'add_cart_item' ), 10, 1 );
}
/**
* Adjust the price of the booking product based on booking properties
*
* @param mixed $cart_item
* @return array cart item
*/
public function add_cart_item( $cart_item ) {
if ( ! empty( $cart_item['booking'] ) && ! empty( $cart_item['booking']['_cost'] ) ) {
$cart_item['data']->set_price( $cart_item['booking']['_cost'] );
}
return $cart_item;
}
I want to change add_cart_item
function's code into my child theme functions.php
file. I want to know how to override this plugin function.
So I did this :
remove_all_filters('woocommerce_add_cart_item');
add_filter('woocommerce_add_cart_item', 'custom_add_cart_item');
function custom_add_cart_item($cart_item) {
if (empty( $cart_item['booking'] ) && empty( $cart_item['booking']['_cost'] ) ) {
$cart_item['data']->set_price( 2000 );
}
return $cart_item;
}
As you can see, I'm setting price to 2000.
But it does not work.. Thanks for your help !
$cart_item
is array OR object?