-
-
Save NiklasHogefjord/6104328 to your computer and use it in GitHub Desktop.
<?php | |
/** | |
* WooCommerce | |
* -------------- | |
* | |
* Display cart total weight on the cart page | |
* | |
*/ | |
add_action('woocommerce_cart_collaterals', 'myprefix_cart_extra_info'); | |
function myprefix_cart_extra_info() { | |
global $woocommerce; | |
echo '<div class="cart-extra-info">'; | |
echo '<p class="total-weight">' . __('Total Weight:', 'woocommerce'); | |
echo ' ' . $woocommerce->cart->cart_contents_weight . ' ' . get_option('woocommerce_weight_unit'); | |
echo '</p>'; | |
echo '</div>'; | |
} |
Newbie alert: Where do I insert this?
I think you should add the code in the function.php of your theme, miltersen.
HI.. can anybody show me the path to where the code needs to be inserted? Thanks
this works very well, but i want to place before total
Total
Subtotal : $100
Shipping : $100
Total Weight : 1000g <- how to place in here
Total : $200
Thnks before..
in "plugins->woocommerce->templates->cart->cart-totals.php"
search for "" and add this code before
<tr>
<th>Total Weight</th>
<td><?php echo WC()->cart->cart_contents_weight . ' ' . get_option('woocommerce_weight_unit'); ?></td>
</tr>
Just wanted to say that even though I'm a visual designer with very little coding experience, this worked out fabulously. Especially the code by @javiercb. Many thanks.
Hi, owlonline commented on 9 Sep 2013 wrote I would like to also show the weight of each item in the cart as well. Ideally just below the item name. What would be the code for that? - I am also looking to do this, do we have an answer
Don't make any changes in the Plugin files. Just add the below code in Function.php file:
/**
* Add Cart Weight to Cart and Checkout
*/
function wcw_cart() {
global $woocommerce;
if ( WC()->cart->needs_shipping() ) : ?>
<tr class="shipping">
<th><?php _e( 'Weight', 'woocommerce-cart-weight' ); ?></th>
<td><span class="label"><?php echo $woocommerce->cart->cart_contents_weight . ' ' . get_option( 'woocommerce_weight_unit' ); ?></span></td>
</tr>
<?php endif;
}
add_action( 'woocommerce_cart_totals_after_order_total', 'wcw_cart' );
add_action( 'woocommerce_review_order_after_order_total', 'wcw_cart' );
/**
- Add Cart Weight to Mini Cart
*/
function wcw_mini_cart() {
if ( WC()->cart->needs_shipping() ) : ?>
cart->cart_contents_weight . ' ' . get_option( 'woocommerce_weight_unit' ); ?>
}
add_action( 'woocommerce_widget_shopping_cart_before_buttons', 'wcw_mini_cart' );
Hi thanks for this! - Do you know how can i set the weight with a "comma" "," instead a "dot" "."? - alex
Super nice snippet, thanks.
Any suggestion on how to maker it update with the ajax cart?
It only update the value when the page is reffreshed.
Thanks in advance.
Hello @protorob , were you able to find a solution for your query ? I'm having the same problem and were wondering if you could share your findings with me, if you don't mind. Thanks, -nbvcw
Hi @nbvcw - you can use this plugin instead: https://wordpress.org/plugins/woo-cart-weight/
Awesome. this works very well - thanks! I would like to also show the weight of each item in the cart as well. Ideally just below the item name. What would be the code for that?