【问题标题】:Product minim amount multiply by 7 in woocommercewoocommerce中的产品最小数量乘以7
【发布时间】:2017-05-09 07:45:07
【问题描述】:

当用户在购物车上并希望在完成时验证最小金额时,我想在最终下订单。需要乘以 7。

例如.. 我店里有 20 种产品。最小产品数量是任何产品的 7 的乘积。

Ex:
Product with ID:3 & Quantity: 5
Product with ID:13 & Quantity: 2 
   => Total:7 = > Success

Product with ID:2 & Quantity: 3
Product with ID:6 & Quantity: 8
  => Total: 11 => Fail

Product with ID:1 & Quantity: 2
Product with ID:5 & Quantity: 8
Product with ID:11 & Quantity: 4
  => Total: 14 => Success

我该怎么做?这是我尝试过的

function wc_minimum_order_amount() {
    global $woocommerce;
    $minimum = 7;
    if ( $woocommerce->cart->get_cart_total() %  $minimum != 0) {
        $woocommerce->add_error( sprintf( 'You must have an order with a minimum of %s to place your order.' , $minimum ) );
    }
}

【问题讨论】:

    标签: php wordpress woocommerce cart hook-woocommerce


    【解决方案1】:

    更新

    您需要将您的功能挂钩 woocommerce_checkout_process,做你的计算和 显示错误。

    类似这样的:

    add_action('woocommerce_checkout_process', 'wh_wc_minimum_order_amount');
    
    function wh_wc_minimum_order_amount()
    {
        $minimum = 7;
        if (WC()->cart->get_cart_contents_count() % $minimum != 0)
        {
    //      wc_clear_notices();
            wc_add_notice(sprintf('You must have an order with a minimum of %s to place your order.', $minimum), 'error');
        }
    }
    

    代码进入您的活动子主题(或主题)的functions.php 文件。或者也可以在任何插件 php 文件中。
    代码已经过测试并且可以工作。

    希望这会有所帮助!

    【讨论】:

    • 嗨!很好,但是我想在用户单击“下订单”按钮时进行这项工作...当用户下订单时...
    • @Hateres1990:我已经更新了我的答案,请看一下。
    • 我看到它有效,但我需要这个版本。谢谢我的朋友:)
    猜你喜欢
    • 2017-12-10
    • 2019-09-18
    • 1970-01-01
    • 2021-10-31
    • 1970-01-01
    • 2017-08-14
    • 1970-01-01
    • 2019-02-24
    • 2019-07-15
    相关资源
    最近更新 更多