How to tip: set a minimum amount before checkout in wp e commerce, part 2

… This will make more sense if you’ve read part 1 about setting a minimum before checkout.

A solution for if a customer had added enough to the cart to get to the checkout but then removed items and reduced their total below the minimum.

I didn’t want to just get rid of the remove,update and quantity functions that the checkout page provides to customer for each product in their carts. I wanted to retain functionality of the shopping cart while enforcing the minimum for the cart total.

My plan was to continue to check if the cart total was at least 80.00 and if a customer went below that by using the remove, update or quantity options, another note about the minimum would appear and the rest of the checkout form would be hidden.

I hope it goes without saying that you can decide your own minimum amount simply by replacing any instance of 80 or 80.00 with your own number – anywhere you encounter it in any of the example codes.

File affected:shopping_cart_page.php
On line 88 – 89 of shopping_cart_page.php there’s the top of the form hook and the div for the forms.

[php]<?php do_action(‘wpsc_before_shipping_of_shopping_cart’); ?>
<div id=’wpsc_shopping_cart_container’>[/php]

I “hijacked” this section so I could put in my minimum total code:

[php]

<?php do_action(‘wpsc_before_shipping_of_shopping_cart’); ?>
<?php $total = ($GLOBALS[‘wpsc_cart’]->calculate_subtotal() );
if($total < 80):
echo "<br/><h2><span class=\"total_nudge-two\">Our Checkout minimum is 80.00</span></h2>";?>
<span class="checkout-total-label"> <?php echo __(‘Your Total is’, ‘wpsc’); ?>:</span> <span class="total_nudge"> <?php echo wpsc_cart_total(); ?></span><span class="total_nudge-two"><?php echo __(‘. Please re-adjust product amounts’, ‘wpsc’); ?> <a href='<?php get_option("product_list_url");?>’><?php echo __(‘ or return to the product list.’, ‘wpsc’); ?></a></span> <?php endif;?><?php echo __(‘ or return to the product list.’, ‘wpsc’); ?></a></span> <?php endif;?>

<div id=’wpsc_shopping_cart_container’ class="<?php $total = ($GLOBALS[‘wpsc_cart’]->calculate_subtotal() );
if($total < 80): echo "hidden"; endif;?>">

[/php]


The 1st image shows the cart total meets the required minimum. The second image shows how the minimum note is displayed while hiding the forms. To do this all I did was use CSS to hide the entire form set in the div if the minimum was not met.

[css] .hidden .wpsc_checkout_forms {

display:none;

visibility:hidden;

}
[/css]

Make sure to place that line after the line that styles #wpsc_shopping_cart_container in your theme CSS file. I added visibility:hidden as an extra protection in case your theme sets display:block on the div style, visibility:hidden will override that.

Ok, that about does it. I hope this tutorial set was helpful to you. Good luck with your projects!

4 thoughts on “How to tip: set a minimum amount before checkout in wp e commerce, part 2”

  1. This is great use of changes without effecting the core files, would this also be able to be applied for QTY instead of a min $ amount?

    1. Depends. Which quantity minimum are you targeting?
      A minimum quantity for ALL items in the cart ( you must add at least 10 items to the cart) in which case you’d be looking at this: wpsc_cart_item_count();
      A minimum quantity for individual cart items ( you must add at least 10 of this item to the cart) in which case you’d look at this: wpsc_cart_item_quantity();

      I was able to find the calculate subtotal function and hack it to set a price minimum. I haven’t looked very hard but there might be a function that calculates how many items are in the cart – if that is where you want to set the minimum. If you want to set a minimum on individual items ( you must add at least 10 of this item to the cart) then I’d look toward revising your product strategy; bundle the products into sets of ten or however many you want added at a time, instead. Far easier.

  2. First, thanks for this tutorial.
    My problem is I have two shipping regions, each with a minimum amount.
    How could detect the shipping region to calculate it?

    1. Shipping is far more complicated than this hack can handle. You’d need to set or catch a minimum in a different place than the cart widget. I wrote this to stop customers from getting to the checkout before they’d added the minimum price amount to the cart. What you need is bigger than that.

Comments are closed.