• Resolved MikaelG

    (@armbreaker)


    Hi.

    I really like this simple plugin, but there were a couple of changes I made to the php code to make it work correctly. One of the changes is the cause of the weight disappearing in mobile view.

    I did these changes to the file woocommerce-cart-weight.php
    Added the code here and added remarks on the changes, and you are free to use it if you like:

    function wcw_plugin_load_plugin_textdomain() {
        load_plugin_textdomain( 'woocommerce-cart-weight', FALSE, basename( dirname( __FILE__ ) ) . '/lang/' );
    }
    add_action( 'plugins_loaded', 'wcw_plugin_load_plugin_textdomain' );
    
    /**
     * Add Cart Weight to Cart and Checkout
     */
    function wcw_cart() {
    	global $woocommerce;
    	if ( WC()->cart->needs_shipping() ) : ?>
    	    <tr class="total-weight">
                <th><?php _e( 'Total Weight', 'woocommerce-cart-weight' ); ?></th>
                <!-- Added data-title to display correct label in cart & checkout, as this is used as label on mobile view by WooCommerce -->
                <td data-title="<?php _e( 'Total Weight', 'woocommerce-cart-weight' ); ?>"><?php echo $woocommerce->cart->cart_contents_weight . ' ' . get_option( 'woocommerce_weight_unit' ); ?></td>
    	    </tr>
    	<?php endif;
    }
    //add_action( 'woocommerce_cart_totals_after_order_total', 'wcw_cart' );
    //add_action( 'woocommerce_review_order_after_order_total', 'wcw_cart' );
    
    // Removed default actions and added new actions to display cart weight in connection with shipping method.
    add_action( 'woocommerce_cart_totals_before_shipping', 'wcw_cart' );
    add_action( 'woocommerce_review_order_before_shipping', 'wcw_cart' );
    
    /**
     * Add Cart Weight to Mini Cart
     */
    function wcw_mini_cart() {
    	if ( WC()->cart->needs_shipping() ) : ?>
    	    <p class="woocommerce-mini-cart__total total total-weight"><strong><?php echo __( 'Total Weight:', 'woocommerce-cart-weight' ); ?></strong> <?php echo WC()->cart->cart_contents_weight . ' ' . get_option( 'woocommerce_weight_unit' ); ?></p>
    	<?php endif;
    }
    add_action( 'woocommerce_widget_shopping_cart_before_buttons', 'wcw_mini_cart' );

    Best regards,
    Mikael

    • This topic was modified 7 years, 1 month ago by MikaelG.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi Mikael,

    thank you for your feedback. We will analyze this issue.
    If there are any arrangements, I will let you know.

    We apologize for the inconvenience.

    Adrianna

    (@adriannagr)

    @armbreaker

    Hi,

    We have just released a new version of the Cart Weight for WooCommerce plugin, in which the bug has been fixed. Please update.

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

The topic ‘Suggestions on changes in the code’ is closed to new replies.