How do I sell AND price WooCommerce products at fixed quantities?

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.

Read More

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.

Related posts

Leave a Reply

1 comment

  1. 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 of WC_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).

    add_action( 'woocommerce_your_type_add_to_cart', array( $this, 'add_to_cart_template' ) );
    
    function custom_type_add_to_cart_template() {
    
        global $product;
    
        // Load the add to cart template
        wc_get_template(
            'single-product/add-to-cart/your-type.php',
            array(), // you can pass global variables here, ex: your product's "lot" size would be a good idea
            '',
            YOUR_PLUGIN_PATH . '/templates/'
        );
    
    }
    

    Finally, adjust the total price in the cart as $price * $quantity / $lot_size.