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
Asked
Active
Viewed 1,309 times
3
-
What are you using to define your shipping weight bands? – markmoxx Dec 11 '18 at 10:57
2 Answers
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.

LoicTheAztec
- 229,944
- 23
- 356
- 399
-
Hey i've checked your code and it works good. Thanks a lot for your help. I just need you for another thing: this code should be shown only for 1 category of my website and also i've seen there is this code in it: $allowed_weight = 27; i am changing this value for 3 because that message should be shown only for a max weight of 3kg. The problem is that this message is now shown also for a weight bigger than 3 kg. Can you help me? – Valerio D'Orazio Dec 13 '18 at 16:31
-
@ValerioD'Orazio I have updated the code with an if statement that will display the message only if the cart total weight doesn't exceed the allowed weight limit. – LoicTheAztec Dec 13 '18 at 23:25
-
hey man thanks a lot. What about the thing that i need to use that function only with 1 of my shop categories? – Valerio D'Orazio Dec 14 '18 at 08:49
0
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

Harsh Khare
- 507
- 1
- 3
- 13