• I have a website with several million posts (using a custom post type called “case”). They each have a lot of post_meta records (using ACF). I now want to transform them into woocommerce products. I’m using Reigel Gallarde’s plugin which sets up woocommerce to treat any CPTs as products — so far so good.

    However, I want to use the exact same set of variations for each case/product without generating new variation post rows in wp_posts for each and every case. How can I define these variations in PHP alone or some other medium so I don’t jam up the database with millions more rows? Is there a hook that would come in handy? I had trouble finding anything in WooCommerce docs.

    When adding a variation to the cart, the add-to-cart.php REST call seems to require both the attribute slug (e.g., “&attribute_pa_color=orange”) and the variation post ID (“&variation_id=48935701”), or else it won’t add to the cart with the desired variation. The downfall here is that, in the database, the variation post ID is coupled (a child of) with the product post ID. I see that this is a good security practice, but it does not scale so well. If I could add an item to the cart with just with that attribute slug, that would be ideal.

    You can reply to my question here or on StackOverflow:
    http://stackoverflow.com/questions/38807958/how-do-i-create-woocommerce-product-variations-in-code-without-saving-new-record

    https://ww.wp.xz.cn/plugins/woocommerce/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    Variations weren’t built with this in mind. You’ll break a lot of things going about it this way and trying to avoid creating variations on each product.

    If you don’t want to create individual variations per product, then I’m guessing stock and price aren’t a need? Are you just looking to collect extra information? Product Addons may be a better option: https://woocommerce.com/products/product-add-ons/

    There are also extensions that allow you to attach a Ninja Form or Gravity Form to a product.

    Thread Starter amfriedman

    (@amfriedman)

    Thank you Caleb. These are virtual and downloadable products but I need time to generate them when someone places an order. So I want a way for the user to specify the turnaround time they need, which will also change the pricing. User should be able to select 7 days, 5 days, or 3 days in a select box. I want these same variations to be available for every single product globally in one go, without having to save database rows for each product to set it up. Maybe there is something besides variations. I thought I could just hook into a function related to variations to override the default interaction with the database to check for them, but that’s just my theory. How could I make this happen?

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    Product Addons is definitely what you need then. Or one of the forms addon extensions.

    Best to just avoid variations in your case, and add product meta in a simpler way.

    Thread Starter amfriedman

    (@amfriedman)

    I see, this might fit the bill. Do I have to pay every year to keep using this plugin though?

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    WooCommerce.com plugins are yearly subscriptions, but 50% off after the first payment. If you don’t renew – you are still able to use the plugin on your site, but you won’t get updates or support.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘How do I create product variations without generating new posts?’ is closed to new replies.