Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!ISSET($_COOKIE[$cart])) {
- $_COOKIE[$cart] = $array();
- setcookie($cart, time() + (86400 * 30), "/"); // 86400 = 1 day
- }
- // add cart to cookie
- $product_id = 15;
- $qty = 1;
- $_COOKIE['cart'][$product_id] = $qty;
- // update cart
- $product_id = 15;
- $qty = 2;
- $_COOKIE['cart'][$product_id] = $qty;
- // remove item from cart
- $product_id = 15;
- unset($_COOKIE['cart'][$product_id]);
- // check cart
- if (!EMPTY($_COOKIE['cart'])) {
- $cart = $_COOKIE['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