aleclofabbro
aleclofabbro

Reputation: 1699

woocommerce calculate price server-side

I need do sell a product whose price depends on a complex calculation over non-discrete parameters set by the customer on the product page, and also on a custom database query result. How can i calculate the price server-side every time the customer changes parameter-values and apply that price when the customer adds to cart?

i read a similar post whose answer suggests a WC plugin, but even that plugin doesn't satisfy my needs.

Thanks

Upvotes: 2

Views: 397

Answers (1)

mirus
mirus

Reputation: 377

Probably, you should try to use woocommerce_get_price filter

add_filter('woocommerce_get_price', 'get_dynamically_generated_price', 10, 2);

function get_dynamically_generated_price($price, $product) {
    // ... here doing your magic with $price based on $product
    // ...

    return $price;
}

Upvotes: 2

Related Questions