我一直在定制WP Ecommence插件,以便为某个类别的每两个项目启用折扣。我知道类别列在$wpsc_cart
数组中,但这不起作用,我不明白为什么。理想情况下,我想废弃这个以支持更简单的事情,这是针对下面的问题第2部分。
我的代码 -
foreach($wpsc_cart->cart_items->wpsc_cart_item as $cartItemDW){
$ii = 1;
if(in_array('product-type-1',$cartItemDW->category_list) || in_array('product-type-2',$cartItemDW->category_list)){
$ii++;
}
}
//Pull up end count
$prodCount = $ii;
//Round off to even number
if($prodCount % 2){
$prodCount = $prodCount - 1;
}
// Discount for every second one
$prodCount = $prodCount / 2;
// Discount of £70 per second item
$prodCount = $prodCount * 70.00;
// Pass discount to Paypal Array
if($discount > 0){
$paypal_vars += array(
'discount_amount' => $discount
);
}
第2部分
理想情况下,我想了解如何根据表_wpsc_cart_contents
中的项目ID获取类别名称,然后说出它是否属于某些类别,相应地进行折扣,看起来比foreach更容易这可能完全没了。有人可以解释如何根据产品ID获取产品类别吗?
答案 0 :(得分:0)
在foreach项目中找到答案1- -
$prodID = $wpdb->get_row('SELECT * FROM wp_wpsc_item_category_assoc WHERE product_id = "'.$item['prodid'].'"');
if($prodID->category_id == 10 || $prodID->category_id == 5 || $prodID->category_id == 23 || $prodID->category_id == 24 || $prodID->category_id == 25 || $prodID->category_id == 26){
$addQuantity = $item['quantity'];
$i = $i + $addQuantity;
//$i++;
}
然后,在foreach项目后面的2- -
$prodCount = $i;
$discount = 70.00 * ($prodCount / 2);
$data['discount_amount_1'] = number_format(sprintf("%01.2f", $discount),$decimal_places,'.','');