【问题标题】:Apply logical Pricing on Woocommerce Attributes对 Woocommerce 属性应用逻辑定价
【发布时间】:2014-10-19 02:57:24
【问题描述】:

亲爱的,我有一个披萨网站,我正在使用 Woocommerce 插件。我想对属性应用一些价格检查。
我的问题是
我有一个比萨产品,其属性是大小和肉。大小(小,大)肉(鸡肉,donair 肉等)。 我已经对属性进行了检查,当客户选择产品尺寸、小尺寸和一块肉时,默认价格为 10 美元。但是我想在这里应用这个逻辑,当客户选择多于一块肉(额外浇头)时,我想在总价上加 2 美元,例如(10 美元 + 2 美元 = 12)。
请帮帮我??

【问题讨论】:

  • 查看github.com/m4olivei/woocommerce-attribute-pricing 的源代码,它似乎正在按照您想要完成的目标做一些事情。
  • 我当时是通过做 jquery 来做到的...
  • 如果你完全在客户端做;这是否意味着技术购物者可以超越运输成本?甚至可能输入一个负值的运费,从而获得免费餐食?

标签: wordpress woocommerce


【解决方案1】:

请使用此操作在 woocommerce 购物车上添加额外价格。现在您需要处理注释的循环代码并应用简单的登录。现在我已经添加了您将如何工作的摘要。

我已经使用它,现在它正在我的本地系统上运行。

add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );

function add_custom_price( $cart_object ) {
    $custom_price = 10; // This will be your custome price  

    foreach ( $cart_object->cart_contents as $key => $value ) {

        $productid = $value['product_id'];
        $variationArr =$value['variation']; //it is an array have the value : meat and size i.e chicken and small

        //In every loop you can count the number of products .
       //Note: In array($variationArr),It have all the active attribute of this product which is created by admin in woocommece. 
        //so you can search it by loop;
        /*
         * Like
         * foreach($variationArr as $k=>$v)
         * {
         * //here is the variation product size
         * }
         * 
         */

        //Now increase the price.
        $price = $value['data']->price;
        $extraPrice = 2;
        $newPrice   = $price + $extraPrice;
        $value['data']->price = $newPrice; 
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    • 2019-07-25
    • 1970-01-01
    • 2019-04-22
    相关资源
    最近更新 更多