SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot BuyAnswersLinks's Avatar
    Join Date
    Aug 2008
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need help with bulk discount code

    I need help with a bulk discount code for a website. It basically gives a discount for higher quantity. So far what I have is the code below, I have been searching around but I cant get it to work. I am not sure what it is :-s

    PHP Code:
    if($grams 1) {
    $price_pre '11.99';
    }elseif(
    $grams >= and 4) {
    $price_pre '9.65';
    }elseif(
    $grams >= and 6) {
    $price_pre '8.79';
    }elseif(
    $grams >= 6) {
    $price_pre '8.79';
    }else{
    $price_pre '0';

    i appreciate the help

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Like this??
    PHP Code:
    <?php
    $grams 
    4;
    switch(
    true)
    {
        case (
    $grams >= 6): #6 or more
            
    $price 7.79;
        break;

        case (
    $grams >= 4): #between 4 and 6
            
    $price 8.79;
        break;

        case (
    $grams >= 2): #between 2 and 4
            
    $price 9.65;
        break;

        default:
            
    $price 10.00;
        break;
    }
    printf(
        
    'You currently have %d grams which is %01.2f per gram, totalling %01.2f',
        
    $grams,
        
    $price,
        
    $price $grams
    ); #You currently have 4 grams which is 8.79 per gram, totalling 35.16
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    Non-Member thewebhostingdir's Avatar
    Join Date
    Oct 2005
    Posts
    703
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if($grams 1) {
    $price_pre '11.99';
    }elseif(
    $grams >= && $grams 4) {
    $price_pre '9.65';
    }elseif(
    $grams >= && $grams 6) {
    $price_pre '8.79';
    }elseif(
    $grams >= 6) {
    $price_pre '8.79';
    }else{
    $price_pre '0';

    This would work.

  4. #4
    SitePoint Zealot BuyAnswersLinks's Avatar
    Join Date
    Aug 2008
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I very much appreciate your guys help. I am using "thewebhostingdir" code but I can not to get it to work with my other code, maybe you can help. The code is below, and it works with all of the other "productid"s but with the code below makes the grams go to "1", even if you set the grams to any other number.

    PHP Code:
    if($product_id == 'SDE5X') {

    if(
    $grams 1) {
    $price_pre '11.99';
    }elseif(
    $grams >= && $grams 4) {
    $price_pre '9.65';
    }elseif(
    $grams >= && $grams 6) {
    $price_pre '8.79';
    }elseif(
    $grams >= 6) {
    $price_pre '8.79';
    }else{
    $price_pre '0';


    }elseif(
    $product_id == 'SDE10X') {
    $price_pre '16.99';
    }elseif(
    $product_id == 'SDE20X') {
    $price_pre '26.99';

    So if you set the grams to something like:
    $grams = '5';

    then the product id total for will SDE5X will be 11.99, but the other will be the correct price which is the code below;

    $price = round($price_pre * $grams, 2);

    I am not sure what I am doing wrong, and thanks in advance for the help

    Update: here is the code broken down:

    $grams = '5';
    $product_id = 'SDE5X';

    if($product_id == 'SDE5X') {

    if($grams = 1) {
    $price_pre = '11.99';
    }elseif($grams >= 2 && $grams < 4) {
    $price_pre = '9.65';
    }elseif($grams >= 4 && $grams < 6) {
    $price_pre = '8.79';
    }elseif($grams >= 6) {
    $price_pre = '8.79';
    }else{
    $price_pre = '0';
    }

    }elseif($product_id == 'SDE10X') {
    $price_pre = '16.99';
    }elseif($product_id == 'SDE20X') {
    $price_pre = '26.99';
    }

    $price = round($price_pre * $grams, 2);

    echo $price;

  5. #5
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    There is a typo in webhostingdir's code.

    This...
    Code:
    if($grams = 1) {
    Should be...
    Code:
    if($grams == 1) {
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


Bookmarks

Posting Permissions

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