Thread tagged as: Question, Shop

Shop cart remove item without causing form action

Is there a way to run the remove from cart button when the perch cart form has an action without calling that action? So on form submit I want to send the user to checkout: <perch:form id="cart" app="perch_shop" class="cart__form" action="/hires/checkout"> but on remove item I want to keep the user on the cart page. I can't use a link for the submit button as I am setting additional cart-properties which require the form to be submitted to be set and passed through.

Rob Saunders

Rob Saunders 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, you can call perch_shop_remove_from_cart() to programatically remove items from the cart. Have your script remove them from the page and then ping a page back on the server to remove them from the cart using that function.

Thanks. For anyone else, here is how I finally managed it:

(the remove item button) cart.html:

                                    <a href="/hires/remove-item/<perch:cartitem id="productID">" class="remove_cart cart__table__remove">
                          <perch:layout path="svg/icon-dustbin" />

Master Page URL pattern: hires/remove-item/[slug:id]


    //Grab productID passed in on URL
    $url = basename($_SERVER['REQUEST_URI']);
    $keys = parse_url($url); // parse url
    $path = explode("/", $keys['path']); // split path
    $slug = end($path); // slug

    //Remove product
    //Send back to cart
    header('Location: ' . $_SERVER['HTTP_REFERER']);