A product enquiry form for a variable product needs a dynamically configurable field - CF7 cannot deliver this but Ninja Forms is flexible.
Early last year I wrote about using Contact Form 7 Dynamic Text Extension to create a product enquiry form for WooCommerce. I recently received a comment asking:
Hmm, how would we use this with a variable product to get the variable SKU?
Can it be done in CF7?
Getting information about the displayed product is easy as the CF7 Dynamic Text Extension plugin can extract the title and ID and other information about the current post (or product in this case). With a variable product we would need to ask the user to specify the variation they are interested in. This requires creating an input element (e.g. radio buttons or ‘select’ dropdown) with an unknown number of elements. This is where we hit the limitations of Contact Form 7.
I have posed the question in the CF7 and CF7 Dynamic Text Extension support pages but there have not been any replies yet.
Trying Ninja Forms
Ever since I found out that Contact Form 7 was slow I have been thinking about trying Ninja Forms.
I created a default form and added a Select input to it. I have found the developer documentation to be lacking and it is hard to get clear information about the internals from a developer perspective. I think that the documentation has not been updated for version 3 of the plugin – the last blog entry on the front page is from April 2016.
I tried to create a custom field but, regardless of what action I ran it in, the ninja_forms_register_field() function was not available. But I did find another way…
Filter On Render
I somehow found the ‘ninja_forms_render_options’ filter and via this found a post about pre-populating a select field. This looks very promising.
In the form edit area I added a select field and set the field name to select_product_attributes.
I use this in the key name in the email
Then it can be used in the filter code to set the options:
The value is displayed in the email. This this example it is a single letter. It would be better to make it clearer but this is just a proof of concept.
WooCommerce Variations – Another Day’s Work
It should not be difficult to expand the code to get the options from a product’s variations. It’s a busy week for me so I don’t have the time to do this but I will get to it.
It might be better to create two forms, one for simple products (omitting the ‘select’ dropdown) and the other with it. The appropriate form would be appended to the product page. The above filter would only be invoked for variable products.
Hello, We are building a b2b marketplace based on WooComnerce and Dokan, we need to be able to use Ninja-Forms to create a form like the one in the link below: https://eezee.sg/rfq
@Abdelfattah: I don’t think that that form would be easy to create with Ninja Forms. I suggest looking at Gravity Forms. You may be able to ask them a pre-sales questions about whether Gravity Forms can create such a form.
It doesnt work. I tried a few combinations from this website and its not working. I need to send form with the current or choosen variation of the product.