Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Nov 2009
    Location
    Chicago, IL.
    Posts
    198
    Plugin Contributions
    0

    Default Which php variable calls for Total Items in Cart?

    I am trying to do something like this on tpl_shopping_cart_default.php

    Code:
    if ( $cart_quantity == "1" ) {
    	echo "Did you know a second box will ship for free!<br />";
    }
    ?>
    is that right? When there is only one item in shopping cart, I want to display the message above.

    is the variable $cart_quantity right for the number of items in cart?

    ( My first attempt at php, be gentle )

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,887
    Plugin Contributions
    96

    Default Re: Which php variable calls for Total Items in Cart?

    Assuming that "only one" in the shopping cart means that there's only 1 item of any type/product, then what you want is:

    Code:
    if ($_SESSION['cart']->count_contents() == 1) {
      echo "Did you know a second box will ship for free!<br />";
    
    }
    ... of course, it's always good practice to put language-specific stuff in a language file! You could add to /includes/languages/english/YOURTEMPLATE/shopping_cart.php:

    Code:
    define('CART_2ND_FOR_FREE', 'Did you know a second box will ship for free!<br />');
    and then change your template code to

    Code:
    if ($_SESSION['cart']->count_contents() == 1) {
      echo CART_2ND_FOR_FREE;
    
    }

  3. #3
    Join Date
    Nov 2009
    Location
    Chicago, IL.
    Posts
    198
    Plugin Contributions
    0

    Default Re: Which php variable calls for Total Items in Cart?

    You are awesome. I have been reading php resources all day to achieve this. Thank you.

    It works perfectly.

  4. #4
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,887
    Plugin Contributions
    96

    Default Re: Which php variable calls for Total Items in Cart?

    Glad to help! Good luck with your store.

  5. #5
    Join Date
    Nov 2009
    Location
    Chicago, IL.
    Posts
    198
    Plugin Contributions
    0

    Default Re: Which php variable calls for Total Items in Cart?

    Yup!

    Now, with the same statement how can i put another part in there.

    if total items in cart are 3 , display "did you know the 4th box ships free"

    and

    If total item are more between than 4 but less than 12, " did you know upto 12 boxes ship at no extra charge"


    ( of course i will use proper text and define files)

  6. #6
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,887
    Plugin Contributions
    96

    Default Re: Which php variable calls for Total Items in Cart?

    Sure, here you go (with 'hard-coded' language):

    Code:
    $itemsInCart = $_SESSION['cart']->count_contents();
    if ($itemsInCart == 1) {
      echo "Did you know a second box will ship for free!<br />"; 
    } else if ($itemsInCart == 3) {
      echo 'Did you know a fourth box will ship for free!<br />';
    } else if ($itemsInCart > 4 && $itemsInCart < 12) {
      echo 'Did you know that up to 12 boxes ship at no extra charge?<br />';
    }

 

 

Similar Threads

  1. v151 php help please - set variable based on items on order
    By philip937 in forum General Questions
    Replies: 11
    Last Post: 13 Aug 2014, 07:27 PM
  2. v151 Global variable for total shipment weight
    By d0ugparker in forum Built-in Shipping and Payment Modules
    Replies: 2
    Last Post: 21 Sep 2013, 03:58 PM
  3. v151 which file calls tpl_index_product_list.php?
    By archelaus in forum Templates, Stylesheets, Page Layout
    Replies: 21
    Last Post: 8 May 2013, 08:55 AM
  4. knowing which php file calls which?
    By joemind in forum General Questions
    Replies: 0
    Last Post: 15 Oct 2008, 08:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg