WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Woocommerce total cart weight (12 posts)

  1. toto
    Member
    Posted 1 year ago #

    Hi friends how to diplsay total cart weight of all products in the cart?

    Just like Order Total but to display Products Weight Total (kg)

    Im using latest versions of WP and WooCommerce

    http://wordpress.org/extend/plugins/woocommerce/

  2. toto
    Member
    Posted 1 year ago #

    Or Total Dimensions?

  3. mikejolley
    Member
    Plugin Author

    Posted 1 year ago #

    You'd need to loop the items and add it up through code. $woocommerce->cart->get_cart() should give you the items in an array.

  4. toto
    Member
    Posted 1 year ago #

    Hi can you share some example code, or which files to modify or please send a link to example code.
    Many thanks.

  5. mikejolley
    Member
    Plugin Author

    Posted 1 year ago #

    Actually, you can grab the cart weight from this variable: http://wcdocs.woothemes.com/apidocs/source-class-WC_Cart.html#24

    Override the totals template if you want to display the weight in the totals area:
    http://wcdocs.woothemes.com/codex/template-structure/

  6. Andy_P
    Member
    Posted 1 year ago #

    Just copy template file you want to modify to yourtheme/woocommerce
    Keep folder structure for the file location.
    Wherever you want the weight to appear just type
    echo $woocommerce->cart->cart_contents_weight;
    in function context you have to globalise $woocommerce otherwise it won't work e.g.
    function some_function() {
    global $woocommerce;
    echo $woocommerce->cart->cart_contents_weight;
    }

  7. toto
    Member
    Posted 1 year ago #

    Im trying with echo $woocommerce->cart->cart_contents_weight; on the template but it returns only 0 ???

  8. royho
    Member
    Posted 1 year ago #

    You must have global $woocommerce; declared before you call that.

  9. toto
    Member
    Posted 1 year ago #

    Thanks that's working.

    So mean how to retrieve total Weight in (kg) of all products in cart.
    For Example:

    ------------------------
    Cart Subtotal 24,49 €
    Order Total 24,49 €
    Products Weight: 100 kg

  10. toto
    Member
    Posted 1 year ago #

    I see that $woocommerce->cart->cart_contents_weight; return wrong data???

    Its return the total weight only of first product.

    If you have:

    1. Product1 - 300kg
    2. Product2 - 100kg

    $woocommerce->cart->cart_contents_weight; return only 300kg why ?

  11. rezzafr33
    Member
    Posted 1 year ago #

    hi everyone, i manage to show total weight using this code on cart/totals.php

    <tr class="total weight">
       <th><strong><?php _e('Total Weight', 'woocommerce'); ?></strong></th>
         <td><strong><?php
           $total_weight = $woocommerce->cart->cart_contents_weight;
           $total_weight .= ' '.get_option('woocommerce_weight_unit');
           echo $total_weight;
         ?></strong></td>
     </tr>

    anyhow to display total dimensions?

  12. Bokenehandel
    Member
    Posted 1 year ago #

    AWD Weight/Country Shipping is ok but don´t count in the weight of the package. So if someone for example buys something so the total weight for the products article is let say 1800g, they will pay shipping costs for 1800g. But if the package is let say 450g, the total weight will be 2250g, which means I, as a seller must pay a lot more for the shipping than the costumer do. So that will not work. So I wonder if there is a plugin or a script I can put to your plugin AWD Weight/Country Shipping which will consider this (package weight) and count in the total weight for articles AND package in the cart for total shipping costs?

    1. One thing the plugin could calculate on is the articles volume (books in my case). The dimensions I can write in to woocommerce for each article as well as the weight. The weight the plugin AWD Weight/Country Shipping use, but not the dimensions information. The “article volume adding package weight” way of count is one way to go. As an administrator I could put in that if the volume is 60x21x60 mm = 75600 mm3 the calculator in the plugin AWD Weight/Country Shipping would put in an extra 250 g to the total weight (article + package) and so on. If the volume for the bookarticles increase the packagecosts would also increase of course.

    2. Another solution would be for the plugin AWD Weight/Country Shipping to first count the total weight for the articles, and then it could put that weight to one package weight so the total weight for the articles and package is correct. I as an administrator could of course put in values, let say if the total weight is let say 500g for the article the calculator can put to the total weight of package to 250g, so the total weight would be 500 +250g = 750g. Or an administrator could also put in this values: so the calculator would do like this: let say if the total weight is let say 1750g for the article the calculator can put to the total weight of package to 440g, so the total weight will be 1750 (Article weight) +440g (Package weight) = 2190g in total weight. The adding of “weight of package to article weight” is of course another way to go.

    As it is now I can only put in weight and country information. Could you fix the plugin AWD Weight/Country Shipping so an administrator also can write in package values so the total weight will be correct?

    Thanks for all tips and help.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic