Woocommerce price change based on quantity and variation

I am currently building my first site using woocommerce for a client and they are asking me for an increase in price per change and quantity, however I am not sure how. Here's an example of what they are asking for:

Product type: Limestone

Options:

  • Product size:
    • bag 10 kg
    • bag 20 kg
    • bag 40 kg
  • Amount:
    • 1-20

TL; DR , if a customer wants multiple 10kg bags, the price increases by £ 36 at a time, if they want multiple 20kg bags, the price increases by £ 30 at a time, and if they want multiple 40kg bags, the price doubles each time.

I've used woocommerce variations and attributes so far, but now this would require modifying the 3x20 variants that require a different price, which would be easier to change if the assertion is possible like this:

if ($productsize === '10kg') {
   $quantity = 2; //get quantity from textbox $_POST
   $initial_price = 36; //get inital price from woocommerce global variable

   $total_price = $inital_price * $quantity;

   update_price($total_price); //a function to update the price in woocommerce when adding to cart

}

      

Obviously, the above code does not use woocommerce variables, however, doing this for only 3 variations would be easier than manually entering 60 variations of a single product for which we have> 60 on our site.

Thanks in advance for your help.

+3


source to share





All Articles