Answer the question
In order to leave comments, you need to log in
How to change price calculation in woocommerce cart?
Hello uv. developers. Please tell me how to be:
The price for the product is indicated for 1 m (for example, 15.9 rubles).
On the product page, the price for 1 piece is automatically calculated. (for example, 193.8 rubles)
When ordering in the basket (and calculating the total price), of course, the price of the goods is taken, i.e. 15.9 rubles, and it is necessary that the calculated price (193.8) be used per unit of goods.
In the screenshot, in blocks 1, 2, 3, everything is displayed correctly (pure appearance), but in the order (4) the prices of the goods (per kg) are used, but it is necessary for pcs.
Tell me, please, how to be, where to dig? For display, I changed the functions a little, but this display
class-wc-cart.php
public function get_product_subtotal( $product, $quantity ) {
$price = $product->get_price();
$taxable = $product->is_taxable();
if(isset($product->length) && isset($product->attributes['pa_porezka'])) {
$row_price = $price * $quantity*$product->length*$product->attributes['pa_porezka'];
$product_subtotal = wc_price( $row_price );
}
Answer the question
In order to leave comments, you need to log in
It seems to me that you overcomplicated and misthought somewhere.
In the basket and further, order_item gets into the order. This is almost the same as a product, but not a product.
The product is just the original dataset for order_item.
So in order_item you are free to write whatever you want. Any price, title or description.
The main thing is to find the right hooks in the basket and order formation mechanism.
How to store a set of prices and units inside the product is not particularly important. It can be in meta fields, it can be in comments or in separate tables.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question