WooCommerce Product Name in Contact Form 7

I have a woocommerce plugin and a contact form plugin 7.

On the product details page in the tabs below, I have a custom tab with a request. I am pasting one of the forms that I created.

Although I'm just trying to repeat the title of the product on the form so that people cannot fill them out themselves.

This does not work.

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

Does anyone have any ideas?

Thanks in advance

0
source share
3 answers

I don’t know how you added the tab as , about which you did not say anything .

But you can achieve by adding the following code to the theme 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>

! , .

enter image description here

, .

+4

! [_post_title].

, ...

+3

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

Source: https://habr.com/ru/post/1669401/


All Articles