Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- // add cart to session
- $product_id = 15;
- $qty = 1;
- $_SESSION['cart'][$product_id] = $qty;
- // update cart
- $product_id = 15;
- $qty = 2;
- $_SESSION['cart'][$product_id] = $qty;
- // remove item from cart
- $product_id = 15;
- unset($_SESSION['cart'][$product_id]);
- // check cart
- if (!EMPTY($_SESSION['cart'])) {
- $cart = $_SESSION['cart'];
- foreach ($cart as $k => $v) {
- echo 'Product ID: ' .$k;
- echo '<br>';
- echo 'Quantity: ' . $v;
- echo '<br>';
- }
- } else {
- echo 'Cart is empty';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement