function yab_shop_cart_quantity($atts) { extract(lAtts(array('output' => 'single', 'showalways' => '1', 'break' => br, 'label' => 'Quantity: ', 'wraptag' => '', 'class' => ''), $atts)); if ($label) { $label = htmlspecialchars($label); } $cart =& $_SESSION['wfcart']; if (!is_object($cart)) { $cart = new wfCart(); } $qty = 0; $out = ''; if ($output == 'single') { $qty += $cart->itemcount; } else { if ($cart->itemcount > 0) { foreach ($cart->get_contents() as $item) { $qty += $item['qty']; } } } if ($showalways == '1') { $out .= $label . $qty; $out = doTag($out, $wraptag, $class) . $break; } else { if ($cart->itemcount > 0) { $out .= $label . $qty; $out = doTag($out, $wraptag, $class) . $break; } } return $out; }
<?php // wfCart Demo // You must included wfcart.php BEFORE you start the session. include "wfcart.php"; session_start(); // start the session $cart =& $_SESSION['wfcart']; // point $cart to session cart. if (!is_object($cart)) { $cart = new wfCart(); } // if $cart ( $_SESSION['cart'] ) isn't an object, make a new cart // end of header stuff ?> <html><head><title>wfCart Demo</title></head> <body><h3>wfCart Demo</h3> <?php // Usually you would get your products from a database but we'll pretend.. $products = array(); $products[1] = array("id" => 1, "name" => "A Bar of Soap", "price" => 2.0); $products[2] = array("id" => 2, "name" => "Shampoo", "price" => 4.8); $products[3] = array("id" => 3, "name" => "Pizza", "price" => 12.95); // check to see if any items are being added if ($_POST['add']) { $product = $products[$_POST['id']]; $cart->add_item($product['id'], $_POST['qty'], $product['price'], $product['name']); } if ($_POST['remove']) { $rid = intval($_POST['id']);