66
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
/**
* @snippet Show CF7 Form @ WooCommerce Single Product
* @how-to Get tutoraspire.com FREE
* @author Tutor Aspire
* @compatible WooCommerce 5
* @donate $9 https://tutoraspire.com
*/
add_action( 'woocommerce_after_add_to_cart_form', 'tutoraspire_woocommerce_cf7_single_product', 30 );
function tutoraspire_woocommerce_cf7_single_product() {
echo '';
echo '
';
wc_enqueue_js( "
$('#trigger_cf').on('click', function(){
if ( $(this).text() == 'Product Inquiry' ) {
$('#product_inq').css('display','block');
$('input[name='your-subject']').val('" . get_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://businessbloomer.com/enable-woocommerce-customers-request-quote/
But in case you hate plugins and wish to code (or wish to try that), then keep reading 🙂