在woocommerce购物车和结帐时显示重量和剩余重量消息 [英] Display weight and the remaining weight message on woocommerce cart and checkout

查看:62
本文介绍了在woocommerce购物车和结帐时显示重量和剩余重量消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Wordpress上的购物车和结帐"页面中向客户显示一条消息.此消息应显示购物车中产品的重量,并告诉他们剩余的重量要支付相同的运输成本,以便他们可以购买其他具有相同运输成本的产品.有专用的插件吗?谢谢

I need to show to my clients a message in Cart and Checkout page on Wordpress. This message should show the weight of the products in cart and tell them the remaining weight to pay the same shipping cost, so they can buy other products spending the same shipping cost. Is there a dedicated plugin? Thanks

推荐答案

以下代码将在购物车中显示自定义通知,并在结帐页面显示购物车的总重量和剩余重量.您必须在该功能中设置允许的重量限制.

the following code will display a custom notice in cart and checkout pages displaying the cart total weight and the remaining weight. You will have to set the allowed weight limit in the function.

代码:

add_filter( 'woocommerce_before_cart', 'display_total_weight_notice' );
add_filter( 'woocommerce_before_checkout_form', 'display_total_weight_notice' );
function display_total_weight_notice( $message ) {
    // DEFINE the allowed weight limit
    $allowed_weight    = 3;
    $cart_total_weight = WC()->cart->get_cart_contents_weight();

    if( $cart_total_weight <= $allowed_weight ) :

    wc_print_notice( sprintf(
        __( 'Your order has a total weight of %s. The remaining available weight is %s for the current shipping cost' ),
        '<strong>' . wc_format_weight($cart_total_weight) . '</strong>',
        '<strong>' . wc_format_weight($allowed_weight - $cart_total_weight) . '</strong>'
    ),'notice' );
    
    endif;
}

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

Code goes in function.php file of your active child theme (or active theme). Tested and work.

这篇关于在woocommerce购物车和结帐时显示重量和剩余重量消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆