I am facing the issue to update the persistent cart in my WooCommerce cart API when I am update product into the cart by rest api. it is not displayed in my website . and when I am adding the product from the website in the API I will get the product but when adding the product from API the website cart is overridden by the API cart products
my rest api code :
if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
$cart = WC()->instance()->cart;
if ( woo_in_cart( $product_id ) ) {
$cart_id = $cart->generate_cart_id( $product_id );
$cart_item_id = $cart->find_product_in_cart( $cart_id );
$cart->set_quantity( $cart_item_id, $quantity );
} else {
$cart->add_to_cart( $product_id, $quantity );
}
} else {
WC()->cart->add_to_cart( $product_id, $quantity );
}
if ( ! empty( $user_id ) ) {
$full_user_meta['cart'] = WC()->cart->get_cart();;
update_user_meta( $user_id, '_woocommerce_persistent_cart_1', $full_user_meta );
}