The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Posting Variable Products to Woocommerce from Formidable Forms

Labels

This Discussion is public

Notifications

Hi there I am trying to work out the best way to post variable products to Woocommerce from the front end of my WordPress site (for listing holidays). Currently I am using Formidable Forms to capture and submit the data along with a few custom pieces of php.

The current setup is using two forms that are linked together:

Form 1: Posts the parent Woocommerce Product to the tables: wp_posts and wp_postmeta. When I submit Form 1 it sets the post as post_type "product" and sets its product type (taxonomy) as a "Variable product", it also pushes the required serialised array data into the meta_key "_product_attributes" in the wp_postmeta table. The attribute added is called "duration". An example of this data from the the table is:

a:1:{s:11:"pa_duration";a:6:{s:4:"name";s:11:"pa_duration";s:5:"value";s:0:"";s:8:"position";i:0;s:10:"is_visible";i:0;s:12:"is_variation";i:1;s:11:"is_taxonomy";i:1;}}

Form 2: Creates additional posts of post_type "product_variation" and adds to the wp_posts and wp_postmeta tables all the required information such as _regular_price. It also adds an entry for the meta_key "attribute_duration" with the value that matches the serialised array data sent in Form 1.

My problem is that this injection of database data does not seem to translate to a complete variable product in wp-admin.

Despite adding the data to the Database, I still need to head to the post edit page and:

Create the attribute with name "duration" Set its value Set it as used for variations Save

When I have done this I can see my added variations listed on the variations tab, but I also need to assign them to an attribute value.

Do I need to call a WordPress or Woocommerce action hook to get this work after the posts have hit the database?

I have tried to work out what is going on when using the edit product dialogue by scanning this code: https://github.com/woocommerce/woocommerce/blob/master/includes/admin/meta-boxes/class-wc-meta-box-product-data.php but its a bit beyond me.

Any clues would be appreciated as I am still getting to grips with formidable hooks and none of the help desk examples or the documentation seems to address variable product creation completely.

Hi Paul,

Nathanael has two blog posts that address creating functionality along this line: The first gives an overview of using lookup fields to accomplish things with variables. The second has to do with bypassing limitations of a WooCommerce variable product. Perhaps you'll be able to glean something from one of these posts. They don't address code specifically but there might be something in there for you.

Hey Jessica,

Many thanks for the links, I had read the t-shirt example already and it does not really solve my problem, as that is aimed at the end user buying a product.  My use case is for vendors in a mult-vendor store.

It would be really handy if anybody on the forum that nows how to post variable products to Woocommerce could chime in, as that would be a real unique solution in the market place.  Currently the only way to do it from the front end is via the quite costly WC Vendors Pro or We Dev Dokan Pro.  I have a feeling the only solution is via a php function that mimics the steps involved in the user interface.

Currently no other form builder app offers this feature, even We Devs.  I guess they don't offer it in their front end form product as would compete with Dokan.

I have put a project out for tender with a few developers to achieve this with Formidable forms, would anybody else be interested in the solution if I made it available?

 

Cheers

 

Paul

 

 

Hi Paul,

Ah, I see now. You're right - that would indeed be a unique solution in the marketplace. And wow, what a niche that would fill if it gets developed. Thanks for posting!

Hi Paul

Did you manage to solve this issue?

I seem to be facing the same problem now too!

Kind regards

Discussion closed.