# Thread: need help with bulk discount code

1. ## 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 >= 2 and 3 < 4) { \$price_pre = '9.65'; }elseif(\$grams >= 4 and 5 < 6) { \$price_pre = '8.79'; }elseif(\$grams >= 6) { \$price_pre = '8.79'; }else{ \$price_pre = '0'; }  ```
i appreciate the help

2. 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?> ```

3. PHP Code:
``` 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';}  ```
This would work.

4. 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 >= 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';}  ```
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. There is a typo in webhostingdir's code.

This...
Code:
`if(\$grams = 1) {`
Should be...
Code:
`if(\$grams == 1) {`

#### Posting Permissions

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