duanfen1312 2019-04-28 16:00
浏览 45

以批发客户身份登录后更新总订单金额

If the visitor adds a product at a quantity less than required minimum of 10 (5 for example) and logs in afterwards to view the cart page, the price and the quantity value will automatically change for the visitor. But the issue is that the order total did not - the total considers 5 to be the quantity input rather than 10. How could I add a conditional statement where IF the quantity inputed by user for any product is less than the required minimum, automatically update the total with the required quantity of 10?

I've tried to have the jQuery run when the "View Cart" icon is clicked and have the total be automatically updated to the correct quantity.

This is the function that sets the input quantity and minimum quantity to be 10:

function woocommerce_quantity_changes( $args, $product ) {

    if ( current_user_can ('wholesale_customer') ){



    if ( ! is_cart() ) {

        $args['input_value'] = 10;
        $args['max_value'] = -1;
        $args['min_value'] = 10; 
        $args['step'] = 1;

    } else {

        $args['max_value'] = -1; 
        $args['step'] = 1; 
        $args['min_value'] = 10;

    }
    }

    return $args;

}

This is the function that automatically updates the cart:

function cart_refresh_update_qty() { 
    if (is_cart()) { 
        ?> 
        <script type="text/javascript"> 
            jQuery('div.woocommerce').on('change', 'input.qty', function(){ 
                jQuery("[name='update_cart']").trigger("click"); 
            }); 
        </script> 
        <?php 
    } 
}

If a product costs $5.00 at retail price and a non-wholesale user enters in 5 as the quantity, the output is $25.00 in the total, which is correct. If the user logs in as a wholesale customer, the price changes to $2.00 and the expected result is $20.00 since the required minimum is 10. But the actual result is $10.00 (5 * $2.00). If the user initially entered a quantity greater than 10 before logging in, the total automatically adjusts correctly after logging in.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度