How to update cart line item price woocommerce cart?
-
I want to update Woocommerce cart line item price programmatically. When add product into woocommerce cart, then change line item price, after that line item total and cart total updated as per product updated product price.Then line item price become change to product price when add new product to the cart
My code is given bellow
function update_item_cart_data() { global $woocommerce; $product_id = $_REQUEST['product_id']; $quantity = $_REQUEST['quantity']; $price = $_REQUEST['price']; $items = $woocommerce->cart->get_cart(); foreach ( $items as $hash => $value ) { if($hash == $product_id) { $cart_item_key = $hash; $woocommerce->cart->set_quantity($cart_item_key, $quantity); $value['data']->set_price($price); } } $woocommerce->cart->calculate_totals(); }
how can i update cart line item price depending on cart key in woocommerce.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to update cart line item price woocommerce cart?’ is closed to new replies.