• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Damien Carbery - Website Development

Getting You Online & Keeping You There

Getting You Online & Keeping You There Get Started
  • Home
  • Services
  • Maintenance Plans
  • Portfolio
  • Blog
  • About Me
  • Contact
You are here: Home / Website Development / Product Enquiry form for Variable WooCommerce Products

Product Enquiry form for Variable WooCommerce Products

Published: April 30, 2018

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.

Related Posts

Debugging – Figuring It Out Yourself

Learn how to investigate and fix front and back end WordPress issues. Use browser tools and the Query Monitor plugin to help locate the problem.

Product Enquiry form with Ninja Forms

I completed the code for a product enquiry form for a variable product using Ninja Forms.

Contact Form 7 Product Enquiry form for variable products

Watch the variation dropdowns and copy the values to a CF7DTE hidden field.

Reader Interactions

Comments

  1. Abdelfattah Ali says

    May 28, 2020 at 5:38 pm

    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

    Reply
    • damien says

      May 28, 2020 at 9:09 pm

      @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.

      Reply
  2. KobietaKoduje says

    July 23, 2021 at 11:55 am

    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.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Blog Categories

  • Being Green
  • Food
  • Grammar
  • Just Strange
  • Laziness
  • Personal
  • Portfolio
  • Race Reports
  • Shudder
  • Typo
  • Website Development
  • WooCommerce Tips
  • Facebook
  • Twitter

Copyright © 2013–2023 Damien Carbery · Using Genesis Framework · Privacy Policy