Hi @Raj51 ,
In order to remove the free product from the cart you have to work by following the below steps:
STEP 1: Fetch the cart (line items) contents in the cart using the GET API for ajax cart api. You can refer to below link for learning more about GET API for cart. https://shopify.dev/api/ajax/reference/cart#get-locale-cart-js
STEP 2: Once you have fetched the updated line item contents, then search for the free item using its variant id or title whatever better or unique.
STEP 3: Update the quantity of that free item in the cart to 0. Again for this you have to use the POST API for change cart quantity. You can refer to the below link, https://shopify.dev/api/ajax/reference/cart#update-quantities
once you have successfully implemented the approach then bingo! your work is done.
But incase you are not well aware of working with the codes then you need to hire a developer, who can help you achieve what you need. If you wish I should work on this for you then do ping me in person chat.
Thanks
I’ve referred to the links you’ve given but I want to know the exact event on which I can do the ajax request. As when I click on main product remove button on the cart I need to remove both the main and the free product.
You can add the event the event on cart update that is whenever a product is added or removed from the cart. Most probably you can find that function/event in cart.js