产品名称WooCommerce,联系表7 [英] Product Name WooCommerce in Contact Form 7

查看:126
本文介绍了产品名称WooCommerce,联系表7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也有woocommerce插件和contact form 7插件。

I have the woocommerce plugin and the contact form 7 plugin too.

在产品详细信息页面底部的选项卡中,有一个名为查询的自定义选项卡。我正在嵌入我创建的表单之一。

On the product detail page, in the tabs at the bottom I have a custom tab called enquire. I am embedding one of the forms I created.

尽管我只是想在表单中回显产品标题,所以人们不必自己填写。

Although I am just trying to echo the product title in the form so people don't have to fill it up by themselves.

这似乎不起作用..

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

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

<p>Subject<br />
  </p>

<?php echo get_the_title( 'id' ); ?>

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


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

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

有人有什么想法吗?

预先感谢

推荐答案

我不知道您是如何添加制表符的,因为您没有提及任何内容 ..

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

,但是您可以通过在主题 functions.php中添加以下代码来实现

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

添加课程到您的联系表

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

屏幕截图

如果有任何疑问,请发表评论。

Comment if you have any doubt.

这篇关于产品名称WooCommerce,联系表7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆