Add form to summary product page
Paste code in function.php in Child theme
add_action( 'woocommerce_single_product_summary', 'xso_woocommerce_cf7_single_product', 30 );
function xso_woocommerce_cf7_single_product() {
echo '<button type="submit" id="trigger_cf" class="single_add_to_cart_button button alt">Liên hệ tư vấn</button>';
echo '<div id="product_inq" style="display:none">';
echo do_shortcode('[contact-form-7 id="10148" title="Liên hệ tư vấn"]');
echo '</div>';
wc_enqueue_js( "
$('#trigger_cf').on('click', function(){
if ($(this).text() == 'Liên hệ tư vấn' ) {
$('#product_inq').css('display','block');
$('input[name=\"your-subject\"]').val('<?php the_title(); ?>');
$('#trigger_cf').html('Đóng lại');
} else {
$('#product_inq').hide();
$('#trigger_cf').html('Liên hệ tư vấn');
}
});
" );
}Last updated