I have some code for a plugin that is doing an AND statement to work out the data['type'] and then use that in a switch statement as follows;
if($data['type'] != 'Cartthrob_discount_percentage_off_product' AND $data['type'] != 'Cartthrob_discount_percentage_off') continue;
switch($data['type']) {
case 'Cartthrob_discount_amount_off_product' :
// Is this coupon applied to this item?
$coupon_entry_ids = explode(',', $data['entry_ids']);
if(in_array($row['id'], $coupon_entry_ids))
{
// Valid and applied to this product
$discount_applied = $discount_applied + $data['amount_off'];
}
break;
// Percentage Off a Single Product
case 'Cartthrob_discount_percentage_off_product' :
$percentage_off = $data['percentage_off'];
$discount = 0;
// Is this coupon applied to this item?
$coupon_entry_ids = explode(',', $data['entry_ids']);
if(in_array($row['id'], $coupon_entry_ids))
{
// Valid and applied to this product
//$discount = round($row['id'] * ( $data['percentage_off'] / 100 ), 2, PHP_ROUND_HALF_UP);
$discount = round($row['price_before_tax'] * ( $data['percentage_off'] / 100 ), 2, PHP_ROUND_HALF_UP);
$discount_applied = $discount_applied + $discount;
}
break;
case 'Cartthrob_discount_percentage_off' :
$percentage_off = $data['percentage_off'];
$discount = 0;
// discounts are calculated against pre tax price
$discount = round($row['price_before_tax'] * ( $data['percentage_off'] / 100 ), 2, PHP_ROUND_HALF_UP);
$discount_applied = $discount_applied + $discount;
break;
}
This is working fine, but i need to add a check for two further data['type]'s with that first line. I'm wondering if someone could help me change it so that I can add in a check for all of the following data types;
Cartthrob_discount_amount_off_product Cartthrob_discount_percentage_off Cartthrob_discount_percentage_off_product Cartthrob_discount_amount_off_over_x
Thanks, Neil
Aucun commentaire:
Enregistrer un commentaire