Print a Jigoshop Cart Link with Price and Total Items



Here’s a simple function that you can add to your WordPress template to print out a Jigoshop cart amount, total price and link to the cart. It’s useful if you want a small consistent button somewhere in your theme, such as in the header, to link the user easily to the full cart page. To use it simply paste the following into your themes functions.php file:

/**
 * abandon_cart_button
 *
 * Prints a Jigoshop cart button
 *
 * @param  string $prefix
 * @param  string $suffix
 *
 */
if(!function_exists('abandon_cart_button') && class_exists('jigoshop_cart')){

    function abandon_cart_button($prefix = '', $suffix = ''){

        $cart_contents = jigoshop_cart::$cart_contents;

        $output = $prefix;

        if(!empty($cart_contents)){

            $cart_contents_count = jigoshop_cart::$cart_contents_count;

            $output .= $cart_contents_count;
            $output .= ($cart_contents_count == 1) ? ' Item - ' : ' Items - ';
            $output .= jigoshop_cart::get_cart_total();
            $output .= ' <a class="button" href="' .jigoshop_cart::get_cart_url() .'">View Cart</a>';

        }else{

            $output .= 'No Items';

        }

        $output .= $suffix;

        echo $output;
    }
}

And then put the following wherever you want the button to appear:

<?php if(function_exists('abandon_cart_button')) abandon_cart_button('<div id="cart_button">', '</div>'); ?>

The function takes 2 optional parameters, one for content before the output and one for content after. Enjoy.

Comments

Sean Ible on February 29, 2012

This is great work, hopefully we can utilise this widget in an upcoming release of Jigoshop.

Alan on August 25, 2012

Great. Just what I was I looking for. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *