Product Name WooCommerce in Contact Form 7

狂风中的少年 提交于 2019-12-01 14:28:07

I don't know how did you add tab as you have not mentioned anything ..

But you can achieve by adding following code in to your theme's functions.php :

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   
}
    ?>

Also add class to your contact form :

    <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>

Bingo ! You have just achieved what you wanted.

Screen shot

Comment if you have any doubt.

I'm quite surprised! no one mentioned [_post_title].

and here are the list of special mail tags you can use...

Try this one

<?php echo WC_Product::get_formatted_name(); ?>

this button must be inserted into the .php page I inserted the woocommerce folder into tabs.php

    <a href="https://www.yoursite.it/contact/?code=<?php echo urlencode(get_the_title()); ?>"> <button type="button" class="btn btn-primary btn-lg scuro"> <span class="glyphicon glyphicon-search"></span>Contattaci per questo prodotto
Contact us for this product</button></a>

this code must be inserted into cf7

<label> title product
[text code default:get]</label>

no plug-in is needed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!