Display weight and the remaining weight message on woocommerce cart and checkout

喜夏-厌秋 提交于 2020-11-29 09:08:51

问题


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


回答1:


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.

The code:

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;
}

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




回答2:


you can use popup maker plugin for display content or form and shortcode also. The plugin provides you popup shortcode. check this link https://wordpress.org/plugins/popup-maker/ Thanks



来源:https://stackoverflow.com/questions/53721484/display-weight-and-the-remaining-weight-message-on-woocommerce-cart-and-checkout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!