【问题标题】:Display a notice if shipping volume exceed a defined value in Woocommerce如果发货量超过 Woocommerce 中定义的值,则显示通知
【发布时间】:2018-03-17 05:11:17
【问题描述】:

我在侧边栏中的一个小部件中有一些 php 代码,它显示了他们订单的总 m3 量。随着客户添加商品,m3 的价值会增加。

我想在订单量达到 68 立方米(相当于 40 英尺集装箱)时提醒客户。有没有办法从我的 sn-p 中获取值并显示一个通知框?

显示订单量的sn-p正在使用此答案中的代码Displaying total sum of shipping Volume of Woocommerce order on page

提前谢谢有人知道如何实现这一点。

【问题讨论】:

    标签: php wordpress woocommerce cart volume


    【解决方案1】:

    我已经在您的linked question thread 中回答了一个自定义函数,该函数根据 Woocommerce 中设置的测量单位计算购物车体积。

    我在下面的代码中使用 get_cart_volume() 函数以这种方式显示自定义通知:

    add_action( 'template_redirect', 'display_volume_alert' );
    function display_volume_alert(){
        if( get_cart_volume() >= 68 )
            wc_add_notice( __("Your order total volume has reached more than <strong>68 m3</strong>", "woocommerce"), 'notice' );
    }
    

    代码进入您的活动子主题(或活动主题)的 function.php 文件中。经过测试并且可以工作。

    【讨论】:

      猜你喜欢
      • 2021-05-05
      • 1970-01-01
      • 2014-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-21
      • 2017-02-11
      • 2014-08-05
      相关资源
      最近更新 更多