Include and tweak “Enquiry Form” in Single Product Page in your WooCommerce shop.A customer requested to show an “Product Inquiry Form” button on the Single Product Page which would show, On click, a Contact Form with a naturally populated subject (Contact Form 7 module must be introduced obviously).
PHP : Add CF7 to the Single Product Page in WooCommerce
1. Display Button and Echo CF7
[php]
<em><span style=”font-weight: 400;”>add_action( ‘woocommerce_single_product_summary’, ‘wbcom_woocommerce_cf7_single_product’, 30 );</span></em><em><span style=”font-weight: 400;”> </span></em>
<em><span style=”font-weight: 400;”>function wbcom_woocommerce_cf7_single_product() {</span></em>
<em><span style=”font-weight: 400;”>echo ‘<button type=”Send” id=”trigger_cf” class=”single_add_to_cart_button button alt”>Product Inquiry</button>’;</span></em>
<em><span style=”font-weight: 400;”>echo ‘<div id=”product_inq” style=”display:none”>’;</span></em>
<em><span style=”font-weight: 400;”>echo do_shortcode(‘[paste_your_contact_form_7_shortcode_here]’);</span></em>
<em><span style=”font-weight: 400;”>echo ‘</div>’;</span></em>
<em><span style=”font-weight: 400;”>}</span></em><span style=”font-weight: 400;”> </span>
<span style=”font-weight: 400;”>// 2. Echo Javascript: </span>
<span style=”font-weight: 400;”>// a) on click, display CF7</span>
<span style=”font-weight: 400;”>// b) and populate CF7 subject with Product Name</span>
<span style=”font-weight: 400;”>// c) and change CF7 button to “Close”</span><span style=”font-weight: 400;”> </span>
<em><span style=”font-weight: 400;”>add_action( ‘woocommerce_single_product_summary’, ‘wbcom_on_click_show_cf7_and_populate’, 30 );</span></em><em><span style=”font-weight: 400;”> </span></em>
<em><span style=”font-weight: 400;”>function wbcom_on_click_show_cf7_and_populate() {</span></em><em><span style=”font-weight: 400;”> </span></em>
<em><span style=”font-weight: 400;”> ?></span></em>
<em><span style=”font-weight: 400;”> <script type=”text/javascript”></span></em>
<em><span style=”font-weight: 400;”> jQuery(‘#trigger_cf’).on(‘click’, function(){</span></em>
<em><span style=”font-weight: 400;”> if ( jQuery(this).text() == ‘Product Inquiry’ ) {</span></em>
<em><span style=”font-weight: 400;”> jQuery(‘#product_inq’).css(“display”,”block”);</span></em>
<em><span style=”font-weight: 400;”> jQuery(‘input[name=”your-subject”]’).val(‘<?php the_title(); ?>’);</span></em>
<em><span style=”font-weight: 400;”> jQuery(“#trigger_cf”).html(‘Close’); </span></em>
<em><span style=”font-weight: 400;”> } else {</span></em>
<em><span style=”font-weight: 400;”> jQuery(‘#product_inq’).hide();</span></em>
<em><span style=”font-weight: 400;”> jQuery(“#trigger_cf”).html(‘Product Inquiry’); </span></em>
<em><span style=”font-weight: 400;”> }</span></em>
<em><span style=”font-weight: 400;”> });</span></em>
<em><span style=”font-weight: 400;”> </script></span></em>
<em><span style=”font-weight: 400;”> <?php</span></em>
<em><span style=”font-weight: 400;”> </span><span style=”font-weight: 400;”>}</span></em>
[/php]
Is There A Plugin For That?
In the event that you’d love to code however don’t feel 100% sure with PHP code, I chose to search for a solid module that accomplishes a similar outcome.
Free WooCommerce Request a Quote Plugins
Presently, adding a contact structure to the single item page is fine. yet, imagine a scenario where you need a legitimate framework that expels the add to truck catches, makes a custom statement email and enables the client to add various items to the statement demand structure.
YITH WooCommerce Request A Quote. it has good reviews and 10,000+ active installations. Luckily, it can be found in the WordPress repository.
The YITH WooCommerce Request A Quote plugin is very handy. Users can immediately add one or multiple products to the “quote request” form, the admin is then notified and can then send a quotation email back to the user.
With just a single button in detail page of the concerned WooCommerce product, users can create their own list and receive an estimate from the administrators.
Here’s how a single product page looks like after you set up the free plugin: