Saturday 18 June 2016

How to Add new tab with contact form, Product form, Product Inquiry Form in Wordpress, WooCommerce?

1>  Install Contact form 7 plugin first.
    then create new form in it with following code:

 <p>Your Name (required)<br />
        [text* your-name] </p>

    <p>Your Email (required)<br />
        [email* your-email] </p>

    <p class="product_subject">Subject<br />
        [text your-subject class:product_name] </p>

    <p>Your Message<br />
        [textarea your-message] </p>

    <p>[submit "Send"]</p>


2>  Then open themes "function.php" file & put follwing code in it:

add_filter( 'woocommerce_product_tabs', 'product_enquiry_tab' );
function product_enquiry_tab( $tabs ) {

    $tabs['test_tab'] = array(
        'title'     => __( 'Enquire about Product', '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="19" title="Contact form 1_copy"]'); //add your contact form shortcode here ..

    ?>

    <script>
    (function($){
        $(".product_name").val("<?php echo $subject; ?>");
    })(jQuery);
    </script>
    <?php
}
    ?>


Its Done.



For more Interesting, Useful Article & codes visit IT New Code.

Ankit Shah PHP Expert

IT New Code suggest a solution for your problem related to coding, Specially .PHP, Wordpress, WooCommerce, Magento, HTML and CSS. Visit Our website for Information.

1 comments:

 

Copyright @ 2016 IT New Code | Developing Code | Designing Code.

Designed by: Ankit Shah