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.
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)
ciro
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?
Neil Gowran
You can wrap the function with a WooCommerce conditional – https://docs.woocommerce.com/document/conditional-tags/#section-5
LeSScro
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
You could use conditionals on whether the stock is available or not
Brì
Hi!
What if I need to sell some products by weight but some other by unit?
Thank you!
Neil Gowran
You could selectively choose products or product categories with conditional logic
Brì
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!
Brì
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!