Wimmerke
Wimmerke

Reputation: 61

Set product price in WooCommerce by quantity and weight

I don't find how to customize my pricing in my WordPress WebShop with the WooCommerce plugin.

I would like to have:

How is this possible please?

greets Wim

Upvotes: 3

Views: 5588

Answers (1)

XciD
XciD

Reputation: 2617

You can add this on your functions.php

// Filter on cart price
add_filter( 'woocommerce_cart_product_price' ,  'custom_price', 10, 2);
// Filter on product page
add_filter( 'woocommerce_get_price_html' ,      'custom_price', 10, 2);

function custom_price( $price, WC_Product $product ){

    // You can store the unit as custom fields
    $unit = get_post_meta( $product->id, 'unit', true );

    // Then concatenate with the price
    $price .=  $unit;

    return $price;
}

Then you have to add a custom field on each product : Custom Fields

Upvotes: 1

Related Questions