remove from cart when local pickup is chosen

I have box items that are automatically added to my cart based on other items in the cart, but I want to remove them if the customer chooses the local pickup option at checkout. What's the best way to accomplish this? All box items are in a category called "BOX."
Comments
  • fc_adamfc_adam FoxyCart Team
    @puremoxie,

    For performing custom logic based on a customer selecting a shipping rate, that would be best handled with javascript. If you're currently automatically adding products to the cart based on what the customer has already added, I'm guessing you may already be dynamically adding products with javascript - is that right?

    For removing them, you could hook into our customer-shipping-option-select.done javascript event. Within that you can check what shipping event has been selected, and if it's the customer pickup, remove any "BOX" products present in the cart.

    The following code, while untested, should give you an idea of how you can approach this with javascript:
    <script>
    FC.client.on("customer-shipping-option-select.done", function(params) {
    if (params.shipping_service_id == 1234) {
    var remove = "";
    for (var i = 0; i < FC.json.items.length; i++) {
    if (FC.json.items[i].category == "BOX") {
    remove += "&" + i + ":quantity=0&" + i + ":id=" FC.json.items[i].id;
    }
    }

    if (remove != "") {
    FC.client.request("https://" + FC.json.config.store_domain + "/cart?cart=update" + remove).done(function() {
    FC[FC.json.context].render();
    });
    }
    }
    });
    </script>
    I hope that helps! Let us know if you have any further questions
Sign In or Register to comment.