Change WooCommerce Price to be by Weight

You can change the WooCommerce price to be by weight by appending some text after the actual price such as ‘per kg’, this can be done by manipulating 3 filters that display the price in the shop/product page, cart and checkout pages;

woocommerce_get_price_html
woocommerce_cart_item_price
woocommerce_checkout_cart_item_quantity

If all items were to be classified as ‘per kg‘ you could use the filters as below…

In the checkout filter I dropped the ‘per kg’ and just left ‘kg’ as the unit price is not used rather the total price.

woocommerce-checkout-weight woocommerce-by-weight

woocommerce-cart-weight

 

If you need more variations on the weight or to use a per item/unit options consider using ACF with a select field that can easily be changed per product.

 

12 Comments

  1. Esmeralda on August 30, 2023 at 12:24 pm

    Great! And if my shipping rates are based on weight, will this code work? Will Woocommerce think this is a real weight of the product?

  2. yash gupta on August 22, 2020 at 1:46 pm

    Where to add these filter ?? (File location plz)

  3. ciro on June 25, 2020 at 3:32 pm

    HI .. I need you same solutions. Have you solved? I have some products to sell by weight and some other by unit.
    How can I set the price by weight or by unit? Is there a Plugin?

  4. LeSScro on June 21, 2020 at 10:47 am

    Really appreciate. THX.

  5. Muzammil Abbas on June 21, 2020 at 5:43 am

    how to apply to a specific category?

  6. LeSScro on May 20, 2020 at 10:20 am

    hello,

    it’s nice but if u have product without stock, then no price u just see per Kg ?
    Any fix for this configuration ?

    Nice piece of code anyway, very usefull.

    • Neil Gowran on May 21, 2020 at 6:01 am

      You could use conditionals on whether the stock is available or not

  7. Brì on September 15, 2018 at 3:20 pm

    Hi!
    What if I need to sell some products by weight but some other by unit?
    Thank you!

    • Neil Gowran on September 15, 2018 at 11:45 pm

      You could selectively choose products or product categories with conditional logic

      • Brì on September 16, 2018 at 10:04 am

        Hi Neil and thank you very much for your help! I will study this and try to do it by myself!
        Have a nice day!

      • Brì on September 16, 2018 at 10:27 am

        Hi Neil, sorry again. I’ve tried to edit the code you wrote up with an easy

        is_product_category( ‘shirts’ ) {}

        but it doesn’t work. I’m in the shop page or in the single product page but not in the archive of category. So I should be able to say to it that I’m speaking about the single category of the single product… Any advice?
        Really thank you for your time, it’s a huge help!

Leave all Comment