在woocommerce插件文件中class-wc-booking-cart-manager.php
有这个代码
/**
* 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;
}
我想换衣服add_cart_item
函数的代码进入我的子主题functions.php
文件我想知道如何重写这个插件函数。所以我这样做了:
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;
}
如你所见,我把价格定在2000英镑。但它不起作用。。谢谢你的帮助!