0

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 );
}

1 Answer 1

1

Updating woocommerce_persistent_cart_1 is not enough, you have to replace/update the session cart data present in wp_woocommerce_sessions table specific to user id too.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.