I'm trying to get a website I'm working on to update the cart using AJAX instead of having to use the 'Update Cart' button in WooCommerce but I'm running into an issue and I don't know why?
Essentially I have the following function:
function kino_update_quantity() {
$cart = WC()->cart;
$value = $_POST['quantity'];
$product = $_POST['product'];
$cart->set_quantity($product, $value, true);
echo json_encode($cart->total);
wp_die();
}
I expect this function to take an product and quantity from the $_POST variables, set the quantity on this, then return a new total price.
However it's returning a total of 0, this is obviously incorrect. If I refresh the page however the totals have all been updated correctly. Also if I turn the boolean to false on the set_quantity call it returns the original total as expected.
I'm confused by this and any help on this issue would be of great use.