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

  • Esmeralda

    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?

  • yash gupta

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

  • 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?

  • LeSScro

    Really appreciate. THX.

  • Muzammil Abbas

    how to apply to a specific category?

  • 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.

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

    • A

      You could selectively choose products or product categories with conditional logic

      • 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!

      • 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!

Leave your comment