将会员价格限制为数量1

时间:2015-09-29 16:44:32

标签: php wordpress shopp

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

会员代码如下:

/***********************
* 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;

}

0 个答案:

没有答案