• Resolved dev

    (@devksec)


    Hello,

    Our site/products have been configured in grams, but we’d like to show in KG at checkout instead. Is this possible to do ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support WojtekPS

    (@wojtekpyrgies)

    Hi @devksec,

    Thanks for reaching us. To change the weight display from grams to kilograms on your WooCommerce store, you’ll need to make changes to a few template files. These template files control how the weight is displayed in different parts of your store. To ensure the safety of your store’s data, we recommend creating a backup before making any changes.

    Below you will find the steps you need to follow to make the necessary changes:

    1. Locate the template files: Find the template files in the “templates” directory of the Cart Weight for WooCommerce plugin. These 3 files control how the weight is displayed.
    2. Copy all 3 template files: Copy the following three template files from the plugin’s “templates” directory: checkout-review-order-after-order-total.php, widget-shopping-cart-before-buttons.php and cart-totals-after-order-total.php.
    3. Paste them into your theme directory: Paste the copied template files into a directory within your theme. In the template files themselves, you’ll find instructions indicating where you should paste them within your theme.
    4. Edit the template files inside your theme folder and save changes.

    Below you’ll find proposals for changes for each file. Paste the code below into the appropriate files:

    File: checkout-review-order-after-order-total.php

    <?php
    /**
     * The Template for displaying cart weight on checkout page.
     *
     * This template can be overridden by copying it to yourtheme/woo-cart-weight/checkout-review-order-after-order-total.php.
     *
     * @package WPDesk\WooCommerceCartWeight
     *
     * @var $cart_weight float
     */
    
    ?><tr class="total-weight">
    	<th><?php echo esc_attr( __( 'Total Weight', 'woo-cart-weight' ) ); ?></th>
    	<td data-title="<?php echo esc_attr( __( 'Total Weight', 'woo-cart-weight' ) ); ?>">
            <?php
            // Convert weight from grams to kilograms
            $cart_weight_kg = $cart_weight / 1000;
            // Display weight in kilograms with precision up to two decimal places
            echo esc_html( sprintf( '%.2f', $cart_weight_kg ) ) . ' kg';
            ?>
        </td>
    </tr>

    File: widget-shopping-cart-before-buttons.php

    <?php
    /**
     * The Template for displaying cart weight on cart widget.
     *
     * This template can be overridden by copying it to yourtheme/woo-cart-weight/widget-shopping-cart-before-buttons.php.
     *
     * @package WPDesk\WooCommerceCartWeight
     *
     * @var $cart_weight float
     * @var $weight_unit string
     */
    
    ?><p class="woocommerce-mini-cart__total total total-weight">
    	<strong><?php echo esc_attr( __( 'Total Weight:', 'woo-cart-weight' ) ); ?></strong>
        <?php
        // Convert weight from grams to kilograms
        $cart_weight_kg = $cart_weight / 1000;
        // Display weight in kilograms with precision up to two decimal places
        echo esc_html( sprintf( '%.2f', $cart_weight_kg ) ) . ' kg';
        ?>
    </p>

    File: cart-totals-after-order-total.php

    <?php
    /**
     * The Template for displaying cart weight on cart page.
     *
     * This template can be overridden by copying it to yourtheme/woo-cart-weight/cart-totals-after-order-total.php.
     *
     * @package WPDesk\WooCommerceCartWeight
     *
     * @var $cart_weight float
     */
    
    ?><tr class="total-weight">
    	<th><?php echo esc_attr( __( 'Total Weight', 'woo-cart-weight' ) ); ?></th>
    	<td data-title="<?php echo esc_attr( __( 'Total Weight', 'woo-cart-weight' ) ); ?>">
            <?php
            // Convert weight from grams to kilograms
            $cart_weight_kg = $cart_weight / 1000;
            // Display weight in kilograms with precision up to two decimal places
            echo esc_html( sprintf( '%.2f', $cart_weight_kg ) ) . ' kg';
            ?>
        </td>
    </tr>

    Please let me know if this is what you require.

    Regards,

    Wojtek

    Plugin Support WojtekPS

    (@wojtekpyrgies)

    As we didn’t receive any reply I am marking this topic as resolved for now.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show KG instead of Grams’ is closed to new replies.