WordPress.org

Ready to get started?Download WordPress

Forums

Simple Cart & Buy Now
[resolved] How do I add a simple basket in header (4 posts)

  1. jaldhous
    Member
    Posted 1 year ago #

    I want to add dynamic text into the header that will display:
    x items - total £x

    I added this with no success as it does not pick up the basket totals:
    <?php if($cart->itemcount > 0) { ?>
    <?php $i=0;
    foreach($cart->get_contents() as $item) { ?>
    <p><?php echo $item['qty'] ?> items - total <?php echo $currency ?> <?php echo number_format($cart->total,2) ?></p>

    <?php $i ++;
    } ?>
    <?php } ?>

    I wanted to make a seperate file for the widget, but the main checkout page and widget cart run off the same file shopping_cart.php. How can I make the code above work or make a customised version of the shopping_cart.php file that can be used in place of the existing widget?

    http://wordpress.org/extend/plugins/simple-cart-buy-now/

  2. bluey80
    Member
    Plugin Author

    Posted 1 year ago #

    I haven't looked at the code in a while (I'm working on a 2.0 release that should structure things much better), but I think you'll want to look at the widget section at the content near

    class scabnWidget extends WP_Widget {

    in includes/functions.php

    The section calls scabn_cart() which is the common code for the two shopping carts. I would modify it to take an argument:

    $output.= scabn_cart($widget=True);

    Then in shopping_cart you can if a if / else statement on widget=True to see if it is a widget or final checkout page.

    Or you could just hijack it there for your own code scabn_cart-mod() and stop having the two sections call the same function.

    I hope that helps,

  3. jaldhous
    Member
    Posted 1 year ago #

    Thanks that worked great! I went to the functions.php
    class scabnWidget extends WP_Widget { and changed the
    $output .= scabn_cart(); to $output .= scabn_small();
    I copied the entire code for function scabn_cart and renamed it
    function scabn_small and changed the type from 'full' to 'tiny' and updated the template theme from shopping_cart.php to tiny_cart.php

    I then went to tiny_cart.php and updated the code to show:
    3 items = £9.99 by changing the code to:

    <div class="tiny_cart">
    <?php if($cart->itemcount > 0) { ?>
    <p>'><?php echo $item['qty'] ?> items = <?php echo $currency ?><?php echo number_format($cart->total,2) ?></p>
    <?php } else { ?>
    <p>your basket is empty...</div>
    <?php } ?>
    </div>

    You could add images and other attributes as well.

  4. jaldhous
    Member
    Posted 1 year ago #

    <p>'><?php echo $item['qty'] ?> items = <?php echo $currency ?><?php echo number_format($cart->total,2) ?></p>
    should be
    <p><?php echo $item['qty'] ?> items = <?php echo $currency ?><?php echo number_format($cart->total,2) ?></p>

    Enjoy!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic