B
B
Bodrosh2017-06-13 00:46:05
WordPress
Bodrosh, 2017-06-13 00:46:05

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 );
    }

In theory, you need to change the function that stores the values ​​\u200b\u200bin total and subtotal? (go into set_prop, legacy_set_total or somewhere else?)
As I understand it, order information is stored like this: in total - the total amount of the order + shipping, shipping_total - shipping cost
In subtotal - price for 1 item (* qty), or am I wrong? Thank you.
c367132fc408475eb2b63b9f5de25aa6.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WordPress WooCommerce, 2017-06-13
@maxxannik

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 question

Ask a Question

731 491 924 answers to any question