0

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.

This does not seem to be working ..

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

Thanks in advance

Kiwimoisi
  • 4,086
  • 6
  • 33
  • 64

4 Answers4

12

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

enter image description here

Comment if you have any doubt.

Rohil_PHPBeginner
  • 6,002
  • 2
  • 21
  • 32
9

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

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

Reigel Gallarde
  • 64,198
  • 21
  • 121
  • 139
0

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

-1

Try this one

<?php echo WC_Product::get_formatted_name(); ?>
Jordy
  • 948
  • 2
  • 9
  • 28
  • Nothing gets echo .. / This is the structure of the form :

    Your Name (required)
    [text* your-name]

    Your Email (required)
    [email* your-email]

    Subject

    Your Message
    [textarea your-message]

    [submit "Send"]

    – Kiwimoisi Mar 03 '15 at 09:52
  • How do you send the product ID to the contact form. – Jordy Mar 03 '15 at 09:55