• Resolved jaldhous

    (@jaldhous)


    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/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author bluey80

    (@bluey80)

    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,

    Thread Starter jaldhous

    (@jaldhous)

    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.

    Thread Starter jaldhous

    (@jaldhous)

    <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!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How do I add a simple basket in header’ is closed to new replies.