Curious issue that might have a simple answer that’s for whatever reason alluding me.
In my WooCommerce shop I’m trying to sell business cards. I want to sell them in lots of either 200 or 400.
I know how to set the step values and limit the minimum and maximum. The problem is I want the 200 and 400 to be treated as units of 1 and 2 respectively when calculating price – so, say, 200 is $29 and 400 is a discounted $39. What naturally happens is that 200/400 cards is being multiplied by $29/$39 respectively.
I can’t seem to figure this out using any of the available plugins. If I set the step value at 200 I need to set the product pricing at $0.195 ($39/200) in order to the get the correct total but I don’t want the user to see “per (individual) card” pricing in the cart.
Any help is appreciated.
What I would probably do is create a new product type that extends the simple product class. I wasn’t going to get into the code at all, but it looks like I’ve already answered several questions that could be useful to you. This isn’t a complete copy-paste solution as this is a pretty sizable job, but this should get you started.
creating a custom product type
Though I would probably extend
WC_Product_Simple
instead ofWC_Product
because basically this will be the same as a simple product with the following caveats:You add 1 meta field to define your “lot” size.
Define product meta fields for custom product type only
Then create your own add to cart template for that type that uses the “lot” size to manipulate the add to quantity inputs (minimum and step).
Finally, adjust the total price in the cart as
$price * $quantity / $lot_size
.