Forum

Thread tagged as: Problem, Shop

Hide stripe pay button when cart empty

When I empty my cart the stripe pay by card button is still visible at the bottom. Clicking on it brings up the modal asking you to pay for £0. I'm using this as taken from the docs:

<?php
            // Show the cart 
            perch_shop_cart([
                'template'=>'cart/cart.html'
            ]);

            // Show the order addresses
            perch_shop_order_addresses();

            // Show the payment form
            perch_shop_payment_form('stripe');
        ?>

I copied and opened the stripe payment form template and wrapped it with <perch:if id="product_count" match="gt" value="0">...</perch:if> but that doesn't seem to work.

Stephen Turvey

Stephen Turvey 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Is product_count a value in that template? (It won't be unless you pass it in)

No it isn't. How would I pass it in? And is that the best way go about it?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can get the total number of items in the cart with perch_shop_cart_item_count()

if (perch_shop_cart_item_count([], true) > 0) {
    perch_shop_payment_form('stripe');
}