add this code in your theme functions.php
//Custom Code
//send inquiry contactform tab on product detail page
//add_filter( 'woocommerce_product_tabs', 'product_enquiry_tab' );
function product_enquiry_tab( $tabs ) {
$tabs['test_tab'] = array(
'title' => __( 'Send Inquiry', 'woocommerce' ),
'priority' => 50,
'callback' => 'product_enquiry_tab_form'
);
return $tabs;
}
function product_enquiry_tab_form() {
global $product;
//If you want to have product ID also
//$product_id = $product->id;
$subject = "Enquire about ".$product->post->post_title;
echo "<h3>".$subject."</h3>";
echo do_shortcode('[contact-form-7 id="3319" title="popup form"]'); //add your contact form shortcode here ..
?>
<script>
(function($){
$(".product_name").val("<?php echo $subject; ?>");
})(jQuery);
</script>
<?php
}
//send inquiry button on product page
add_filter( 'woocommerce_loop_add_to_cart_link', 'replacing_add_to_cart_button', 10, 2 );
function replacing_add_to_cart_button( $button, $product ) {
$button_text = __("Send Inquiry", "woocommerce");
$subject = $product->post->post_title;
$button = '<a class="button product_send_inquiry_btn" data-title="'.$subject.'" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
return $button;
}
//send inquiry button on product detail page
add_action( 'woocommerce_single_product_summary', 'my_extra_button_on_product_page', 36);
function my_extra_button_on_product_page() {
global $product,$post;
$button_text = __("Send Inquiry", "woocommerce");
$subject = get_post_field('post_title', $post->ID);
$button = '<a class="button product_send_inquiry_btn" data-title="'.$subject.'" >' . $button_text . '</a>';
echo $button;
}
//get product name on button click script add in footer
add_action('wp_footer', 'add_send_btn_script');
function add_send_btn_script() {
?>
<script>
jQuery('.product_send_inquiry_btn').on('click', function (e) {
e.preventDefault();
var product_name = "Product Inquiry for "+jQuery(this).data('title');
jQuery(".product_name").val(product_name);
});
</script>
<?php
return true;
}
No comments:
Post a Comment