2

我正在使用适用于 WP 的 Shopp 插件。我们有一个自定义的“会员定价”系统写入我们的 functions.php 文件,我无法弄清楚如何将此定价限制为每个项目之一。澄清一下,如果会员将 2 件商品 A 添加到购物车,他们应该会看到其中一件商品的特价和另一件商品的全价商品。谢谢!

会员代码如下:

/***********************
* SET PRICE BASED ON CLIENT TYPE
************************/

add_action('shopp_cart_add_item', 'my_function');
function my_function ( $Item ) {
global $Shopp, $current_user;


//only override price if we have a client type
if(count($_SESSION['userdata']->ClientTypes) > 0)
{
    //check to see if there is a special price for this product

    $prices = get_field('client_type_prices', $Item->product);

    //reset for each prouct
    $setspecial = FALSE;
    $setprice = "";

    foreach($prices as $price)
    {
        //get our client type unique id
        $unique_id = get_field('unique_id', $price['client_type']->ID);

        if(in_array($unique_id, $_SESSION['clienttypes']))
        {

            if(($price['price'] < $setprice) || ($setprice == "")){
                $setprice = $price['price'];
                $setspecial = TRUE;
            }
        }

    }

    //only actually override the price if a modified price has been entered for the item/type
    if($setspecial)
    {
        $Item->unitprice = $setprice;
        $Item->data->priced = $setprice;
    }

}

return $Item;

}
4

0 回答 0