Reputation: 4182
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
Upvotes: 0
Views: 21868
Reputation: 71
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
Upvotes: 0
Reputation: 65254
I'm quite surprised! no one mentioned [_post_title]
.
and here are the list of special mail tags you can use...
Upvotes: 9
Reputation: 6080
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.
Upvotes: 13