• Resolved greatlandgrocery

    (@greatlandgrocery)


    Hi,

    Is it possible to have the plug-in show a truncated cart weight total without the decimals. As an example, I will frequently get weights displayed with very long decimals (i.e. 19.753125 lbs). How can I get the plugin to display only the whole number without the decimals (i.e. 19 lbs)?

    There is a previous post about this fix, however, when I tried implementing this code into the plugin’s php file, it ended up crashing the checkout page. Is there another fix for this that would work?

    Thank you!

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @greatlandgrocery

    Please edit the plugin file woocommerce-cart-weight.php and replace lines 4452 with following PHP code:

    function wcw_cart() {
    	global $woocommerce;
    	if ( WC()->cart->needs_shipping() ) : ?>
    	    <tr class="total-weight">
                <th><?php _e( 'Total Weight', 'woocommerce-cart-weight' ); ?></th>
                <td data-title="<?php echo __( 'Total Weight', 'woocommerce-cart-weight' ); ?>"><?php
    $crazyweight = $woocommerce->cart->cart_contents_weight ;
    $cartweight = sprintf("%.2f", $crazyweight);
    $weight_unit = get_option('woocommerce_weight_unit');
    echo $cartweight . " " . $weight_unit;
    ?></td>
    	    </tr>
    	<?php endif;
    }
    Thread Starter greatlandgrocery

    (@greatlandgrocery)

    Thank you! That code solved the issue here and is working great!

    Thread Starter greatlandgrocery

    (@greatlandgrocery)

    Hi, again!

    Thank you for your previous support with this ticket! I ran the plugin update that was released shortly after this fix was implemented and the changes were overwritten. I’ve tried to implement this solution again, but can’t seem to get this to work. Is there a revision of the code that would work the latest version of the plugin (V 1.2.1)?

    @greatlandgrocery
    Sure 🙂

    Just edit the file classes/Plugin.php and replace lines 57-60 with following code:

    <tr class="total-weight">
    <th><?php esc_attr_e( 'Total Weight', 'woocommerce-cart-weight' ); ?></th>
    <td data-title="<?php echo esc_attr__( 'Total Weight', 'woocommerce-cart-weight' ); ?>"><?php
    $crazyweight = $cart_weight ;
    $cartweight = sprintf("%.2f", $crazyweight);
    $weight_unit = get_option('woocommerce_weight_unit');
    echo $cartweight . " " . $weight_unit;
    ?></td>
    </tr>

    All the best!

    Thread Starter greatlandgrocery

    (@greatlandgrocery)

    This works great… Thank you very much for the support!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Round Shipping Weights’ is closed to new replies.