wp电子商务折扣 - 如果产品属于类别

时间:2013-05-28 20:16:02

标签: php wordpress wordpress-plugin e-commerce

我一直在定制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获取产品类别吗?

提前谢谢。丹

1 个答案:

答案 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,'.','');