With WooCommerce, I use Contact Form 7 and Product Info Request plugins to add a form inside a single product pages, because I need a functionality that allow users to send an enquiry request about products (thought simple contact form).
You can understand seeing this screenshot:
All my product are variable product with variations (from attributes).
Is there any way to retrieve the selected variations by the customer and send it via contact form 7?
For example :
User select the color black and size s, then fill the form and when the email is send, in addition to Receive the classic information (name, email ecc..) I receive also the attribute selected (in this case black
and s
)
I have tested it and it will not send any data related to chosen variations, because it is just outputting the selected contact form below add-to-cart button (in single products pages). Additionally this plugin hasn't been updated since more than 2 years, so it's some kind of outdated.
I have found this related answer: Product Name WooCommerce in Contact Form 7
It explains how to set a contact form 7 shortcode in a product tab and displaying the chosen product title in the email.
So from this answer I have transposed the code, to use it just as the plugin was doing (just below the add to cart button).
Here in this example/answer I have set in my variable product 2 attributes for the product variations:
Color
andSize
.This are my settings
Contact form 7
for the form that I will use in my code:Here I have add this text field
[text your-product class:product_details]
. so you will need to add also in your "mail" settings tab[your-product]
tag inside the "message body", to get that in your email:The PHP code custom funtion hooked in
woocommerce_after_add_to_cart_form
action hook:Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Here are the screen shoots from my test server:
The product with the selected attributes:
What I get on the form (I dont hide the special text field to show you the pulled data by jQuery):
As you see, you get the data you need to send in your email…
Once I have selected the attributes of the product and filled the other fields of the form, when I submit this form I get, this email message:
So everithing is working just as you expected and this is a working tested example answer.