what I am trying to achive is if user adds a particual product in cart its price should change to zero

Here is the simple code snippet which I am using to update cart item price but

function set_bonus_product_pice($cart_object){
     if ( is_admin() && ! defined( 'DOING_AJAX' ) )

       $free_product_ID = 10;
       foreach ( $cart_object->cart_contents as $key=>$cart_item) { 
           if($cart_item['product_id'] == $free_product_ID){

I also tried dubugging it further it works fine until wc_get_price_excluding_tax method is called in class-wc-cart.php file , some how wc_get_price_excluding_tax method removes the change from product object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.