【问题标题】:Dynamic progress bar in WooCommerceWooCommerce 中的动态进度条
【发布时间】:2019-05-31 13:31:18
【问题描述】:

我使用在购物车页面上显示消息“您当前的订单总数是%s 来下订单”的代码,并锁定按钮,直到客户收集到一定数量的正确数量的产品。

代码如下:

/* Set a minimum order amount for checkout */
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );

function wc_minimum_order_amount() {
    // Set this variable to specify a minimum order value
    $minimum = 1000;

    if ( WC()->cart->total < $minimum ) {

        if( is_cart() ) {

            wc_print_notice( 
                sprintf( 'Your current order total is %s — you must have an order with a minimum of %s to place your order ' , 
                    wc_price( WC()->cart->total ), 
                    wc_price( $minimum )
                ), 'error' 
            );

        } else {

            wc_add_notice( 
                sprintf( 'Your current order total is %s — you must have an order with a minimum of %s to place your order' , 
                    wc_price( WC()->cart->total ), 
                    wc_price( $minimum )
                ), 'error' 
            );

        }
    }
}

如何根据这段代码制作进度条?向客户清楚地显示了订单的最低数量以及他添加了多少产品。

例如基于此:Dynamic Progress Bar with Labels

我在 WooCommerce 中找不到类似的东西。我希望这段代码对许多开发者有用。

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:

    作为选项,您可以使用 JavaScript 来实现。 当您的网站加载购物车页面时,通过挂钩或更改模板页面打印具有当前订单总额的 JS 代码。 接下来,当带有数量选择器的按钮更新时,您会显示包含所需数据的进度条。

    【讨论】:

    • 感谢您的回答。你能举个例子的代码吗?
    • 可取、可插入、一切正常的代码,我就不写了。这个太长了。您可以开始编码,如果您在此过程中遇到一些问题,请询问。我可以帮助一些明确的事情(如何得到一些东西,改变它或如何将它插入到代码中......)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-11
    • 1970-01-01
    • 2023-03-15
    相关资源
    最近更新 更多