woocommerce - woocommerce_before_calculate_totals hook stopped working after update to WC 3.0.1 -
i have updated wc 3.0.1 2.6.14.
original code follows:
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' ); function add_custom_price( $cart_object ) { $custom_price = 10; // custome price foreach ( $cart_object->cart_contents $key => $value ) { $value['data']->price = $custom_price; } } it no longer updating price in cart or minicart.
for overriding product price on cart in latest version of woocommerce (3.0.1) try using set_price( $price ) function in woocommerce help. source here
add_action( 'woocommerce_before_calculate_totals', 'woocommerce_pj_update_price', 99 ); function woocommerce_pj_update_price() { $custom_price = $_cookie["donation"]; // custom price $target_product_id = 413; //product id foreach ( wc()->cart->get_cart() $cart_item_key => $cart_item ) { if($cart_item['data']->get_id() == $target_product_id){ $cart_item['data']->set_price($custom_price); } } }
Comments
Post a Comment