0

I'm stuck, don't know how we can change price against individual price in woocommerce.

Currently, Cart object provide us a single object against a single product doesn't really matter, how much quantity you have in the bucket due to below mentioned code in class-wc-cart.php.

if ( $cart_item_key ) {
            $new_quantity = $quantity + $this->cart_contents[ $cart_item_key ]['quantity'];
            $this->set_quantity( $cart_item_key, $new_quantity, false );
        }

What I'm looking?

Suppose you have product with price of 200$, and customer push this product into cart so the quantity is 1 and in the same cart, if the customer either change quantity from input or click on add to cart button for the same product, then every time the price will be 20$ instead of the 200$.

That's what the issue, I don't understand how to do that, could you please help me to figure this out, it will be more helpful and means allot to me.

Orela Studio
  • 35
  • 1
  • 4

1 Answers1

1

You need to research a little more. I ran what your asking thru Google here are the first three results. Anyone of these three links can get you started.

Change cart item prices in Woocommerce 3

https://rudrastyh.com/woocommerce/change-product-prices-in-cart.html

https://www.webroomtech.com/change-product-price-when-other-product-is-in-cart-woocommerce/

InvictusMKS
  • 401
  • 3
  • 8
  • You're right, I did research about all these stuffs and came up with the solution, we have to skip first quantity and for rest of the quantities it should be multiple with 20, then sum up the whole value and divide it with 2. Because setprice method works for individual item and multiple with the quantity. – Orela Studio Nov 19 '21 at 10:30
  • What do you think, if I'm on the right track – Orela Studio Nov 19 '21 at 10:30
  • @OrelaStudio I can't remember exactly the process I used when implementing something similar. Can you not check if the product you are adding is already in the cart? If it is get the quantity it'll be once that product is added and then set price equal to 200 + (20 * (total_product_qty - 1)) – InvictusMKS Nov 19 '21 at 14:24