WooCommerce: Product Enquiry Form @ Single Product Page (CF7)

Published by axmin on

A client asked to show a “Product Inquiry” button on the Single Product Page which would display, upon click, a Contact Form with an automatically populated subject (Contact Form 7 plugin must be installed of course). Here’s how I did it!

PHP Snippet: Add CF7 to the Single Product Page – WooCommerce


add_action( 'woocommerce_after_add_to_cart_form', 'bbloomer_woocommerce_cf7_single_product', 30 );
  
function bbloomer_woocommerce_cf7_single_product() {
   echo '<button type="submit" id="trigger_cf" class="single_add_to_cart_button button alt">Product Inquiry</button>';
   echo '
';
   wc_enqueue_js( "
      $('#trigger_cf').on('click', function(){
         if ( $(this).text() == 'Product Inquiry' ) {
            $('#product_inq').css('display','block');
            $('input[name=\'your-subject\']').val('" . the_title() . "');
            $('#trigger_cf').html('Close');
         } else {
            $('#product_inq').hide();
            $('#trigger_cf').html('Product Inquiry');
         }
      });
   " );
}

Is There a Plugin For That?

If you’d love to code but don’t feel 100% confident with PHP, I decided to look for a reliable plugin that achieves the same result.

Actually, in this case, I wrote a full tutorial – it covers many plugin alternatives and gives you screenshots and links. Here it is: https://axio.ir/enable-woocommerce-customers-request-quote/

But in case you hate plugins and wish to code (or wish to try that), then keep reading

Categories: Woocommerce

0 Comments

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

fa_IRفارسی