I'm developing an e-commerce website. I'm trying to set a cart item quantity using an ajax request.
I got this
if (isset($_POST['product_id']) && isset($_POST['new_quantity'])) {
global $woocommerce;
$woocommerce->cart->set_quantity($_POST['product_id'], $_POST['new_quantity']);
}
I also tried with
WC()->....
but it doesn't work and throws this error
Call to a member function needs_shipping() on null in C:\xampp\htdocs\findandcandy\wp-content\plugins\woocommerce\includes\class-wc-cart.php on line 1514
What can be causing this to happen?
If you need me to show some more code please tell me. Thanks