0
votes

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 add anything more to the database? Is there a hook for creating a variation on the fly? 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.

1

1 Answers

0
votes

Since I really just wanted the same set of variations for every single product, I ended up taking a different approach. I simply need to use the WooCommerce Product Add-Ons plugin to create a global form. This form displays on every product page and appears to be working even for CPTs that are treated as products. It does NOT create new postmeta fields for every single CPT, which is what I needed.