Support » Plugin: Build a Headless WooCommerce store with CoCart » Remove cart Item not working

  • Resolved shaileshprajapati

    (@shaileshprajapati)


    $_REQUEST[‘cart_item_key’] = ‘26657d5ff9020d2abefe558796b99584’;

    $curl = curl_init();

    $args[‘cart_item_key’] = $_REQUEST[‘cart_item_key’];

    curl_setopt_array( $curl, array(
    CURLOPT_URL => $base_url.”/wp-json/cocart/v1/item”,
    CURLOPT_CUSTOMREQUEST => “DELETE”,
    CURLOPT_POSTFIELDS => $args,
    CURLOPT_RETURNTRANSFER => true,
    ) );

    $response = curl_exec($curl);

    curl_close($curl);

    echo $response;
    ——————————-
    Please check this code, remove cart item not working, it says “No items in cart”.

    Please suggests

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Sébastien Dumont

    (@sebd86)

    Hello.

    “No items in cart” means the cart is empty. If it said “Item in cart does not exist” then it would be because the cart item key was incorrect but there are no items to begin with.

    Is the cart for a guest customer?

    Thread Starter shaileshprajapati

    (@shaileshprajapati)

    yes it is for guest customer and cart item key also exist.

    Plugin Author Sébastien Dumont

    (@sebd86)

    What method for guest customers are you using and what code language?

    Thread Starter shaileshprajapati

    (@shaileshprajapati)

    <?php
    include(‘config.php’);

    $args[‘cart_key’] = $_REQUEST[‘cart_key’]; // this is generated by us
    $args[‘product_id’] = $_REQUEST[‘product_id’];
    $args[‘quantity’] = $_REQUEST[‘quantity’];

    if( $_REQUEST[‘product_type’] == ‘variable’ ) {
    $args[‘variation_id’] = $_REQUEST[‘variation_id’];
    foreach($_POST[‘variations’] as $key => $value)
    {
    $args[‘variation’][$key] = $value;
    }
    }

    $curl = curl_init();

    curl_setopt_array( $curl, array(
    CURLOPT_URL => $base_url.”/wp-json/cocart/v1/add-item”,
    CURLOPT_CUSTOMREQUEST => “POST”,
    CURLOPT_POSTFIELDS => $args,
    CURLOPT_RETURNTRANSFER => true
    ) );

    $response = curl_exec($curl);

    curl_close($curl);

    echo $response;


    We are using above code to add item to the cart. Please check it

    Plugin Author Sébastien Dumont

    (@sebd86)

    Your code looks fine to me. Latest patch should help too.

    Thread Starter shaileshprajapati

    (@shaileshprajapati)

    Please let me know what should cause the issue ?

    Thread Starter shaileshprajapati

    (@shaileshprajapati)

    Which latest patch are you suggesting to do ?

    Plugin Author Sébastien Dumont

    (@sebd86)

    Update CoCart.

    Thread Starter shaileshprajapati

    (@shaileshprajapati)

    I have updated the plugin but I am getting the same response:
    {“code”:”cocart_no_items”,”message”:”No items in cart.”,”data”:{“status”:404}}

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Remove cart Item not working’ is closed to new replies.