Support » Plugin: WordPress Simple PayPal Shopping Cart » Display number of items in cart

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor mbrsolution

    (@mbrsolution)

    Hi davep87, try the following post.

    Let us know if that is what you are after.

    Kind regards

    Hi, thanks for your quick response

    I saw that one, but isn’t that for the number of lines or different products rather than total number of items in the basket?

    If someone is ordering 3 apples, 3 oranges and 1 banana i’d like it say 7 rather than 3..

    Plugin Author mra13

    (@mra13)

    The following should do it.

    <?php foreach ($_SESSION['simpleCart'] as $item)
    {
    $sub_total += $item['price'] * $item['quantity'];
    $total_items += $item['quantity'];
    }
    echo "Total Items: ".$total_items;
    echo "Sub Total: ".$sub_total;
    ?>

    I have added a function for it too so in the new version there will be a function that you can call.

    Thank you!

    Although i’m getting a ‘Invalid argument supplied for foreach() in X on line X’ error, i’ve tried having a play but can’t seem to fix it?

    Realised it was because there was nothing in the cart, the above code will need to be changed so that it only runs when there is something in the cart?

    What was the conclusion to this issue? I’m looking for the same solution but noticed the code needed to be changed.

    Any help would be greatly appreciated.

    Plugin Author mra13

    (@mra13)

    Here is another example snippet. The following will only run if there is something in the cart:

    if (isset($_SESSION['simpleCart']) && is_array($_SESSION['simpleCart']))
    {
        foreach ($_SESSION['simpleCart'] as $item)
        {
            $sub_total += $item['price'] * $item['quantity'];
            $total_items += $item['quantity'];
        }
        echo "Total Items: ".$total_items;
        echo "Sub Total: ".$sub_total;
    }

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Display number of items in cart’ is closed to new replies.