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

With one of my current projects I was asked if I could set a minimum amount for customers to add to the cart before they could get to the checkout. FYI, I began the project when the wp e commerce plugin version was still 3.7.8, this is the version that the following template files reference:

cart_widget.php
shopping_cart_page.php
wpsc-includes/display.functions.php

File affected:cart_widget.php

Just to acclimate you to the area of the file we need to add to, in cart_widget.php at line 70 there is a form for clearing the cart. On line 77 begins the HTML for displaying the Go to Checkout link if any items are in the cart. What I did was just hijack this function to insert a conditional statement that unless the cart total is a minimum of 80.00 to show a little note about the cart minimum. Once the cart total is 80.00 then it can show the Go to Checkout link.

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.

[php]

<div class=’gocheckout’>

<?php $total = ($GLOBALS[‘wpsc_cart’]->calculate_subtotal() );
if($total < 80):
echo "<span class=\"total_nudge\">Checkout minimum is 80.00</span>"; endif;?>

<?php $total = ($GLOBALS[‘wpsc_cart’]->calculate_subtotal() );
if($total >= 80): ?>

<a href='<?php echo get_option(‘shopping_cart_url’); ?>’><?php echo __(‘Go to Checkout’, ‘wpsc’); ?></a>
<?php endif;?>

</div>

<?php else: ?>

<p class="empty">
<?php echo __(‘Your cart contains’, ‘wpsc’); ?> <span class="emptyisthecart"> <?php echo __(‘0’, ‘wpsc’); ?> </span> <?php echo __(‘items’, ‘wpsc’); ?>

</p>

<?php endif; ?>
[/php]

In the images you can see examples of the changes.


If you examine the 1st image you’ll see that I removed the continue shopping and go to checkout links from the Fancy Notification box. The reasoning was I did not want people to be able to click through to checkout and I also didn’t want to have to add new code to a core file so it was just easier to take out the links.

Editing core files of a plugin is usually not a good idea:upgrades will overwrite the changes that might be tricky to put back in while removing a few lines of HTML is much easier.

File affected: wpsc-includes/display.functions.php lines 146 to 155

[php]
function fancy_notification_content($cart_messages) {
global $wpdb;
$siteurl = get_option(‘siteurl’);
foreach((array)$cart_messages as $cart_message) {
$output .= "<span>".$cart_message."</span>";
}
$output .= "<a href=’".get_option(‘shopping_cart_url’)."’ class=’go_to_checkout’>".__(”, ‘wpsc’)."</a>";
$output .= "<a href=’#’ onclick=’jQuery(\"#fancy_notification\").css(\"display\", \"none\"); return false;’ class=’continue_shopping’>".__(‘X’, ‘wpsc’)."</a>";
return $output;
}[/php]

The easiest thing of all would be to not use Fancy Notifications although the option conveys to the customer that they’ve added an item to the cart and,depending on your shopping cart widget style or placement, this might not be so obvious. Just something to keep in mind.

Just doing this much took care of the client’s request. But that was not good enough for me, overachiever that I am I had to think ahead to what would happen 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.

The solution is provided in part 2.

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!

How to TIP: Customizing Xsilva Lightspeed Web Store

If you’re given the assignment to customize Web Store you might start out with the feeling that you are limited in what you can do as far as Web Store’s templating system goes.
We all know by now that each tpl.php in each template package – Deluxe or Framework – is included by one main file: index.tpl.php. That means that this file runs the whole show for every section of the online store. This means that if you add a block to index.tpl.php and you don’t know how to use PHP to hide it and you don’t want it to show on every section, it will.

Luckily, we can use the unique form ID that Web Store creates for Categories, Products, Cart and Checkout and more.
Because the form element that generates a unique ID is listed in the document right after the body element we can use it like we would use a unique id or class in the body element.

  • List of XLSWS Form IDs:

  • #xlsws_product = a single product details page
  • #xlsws_category = a single category page
  • #xlsws_cart = the edit cart page
  • #xlsws_checkout = the checkout page
  • #xlsws_gregistry = a single wishlist page
  • #xlsws_myaccount = an account page
  • #xlsws_custom_page = a single custom page
  • #xlsws_sitemap = the site map page
  • #xlsws_contact_us = the contact us page

Practical application:

Say you’ve got a block of content and you added it to index.tpl.php but for whatever reason you don’t want this content to show on a single product details page.

You could add this to webstore.css

[css]
#xlsws_product #block-you-dont-want-toshow {display:none;}
[/css]

Try it out for yourself & good luck with all your projects!