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.

 

4 Comments

  1. 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 a Comment