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

前端 未结 2 1675
陌清茗
陌清茗 2021-01-20 12:00

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

相关标签:
2条回答
  • 2021-01-20 12:18

    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

    0 讨论(0)
  • 2021-01-20 12:21

    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.

    0 讨论(0)
提交回复
热议问题