Last active
August 25, 2023 17:36
-
-
Save damiencarbery/f7db36de7a875b6b9b4d10ff61597f60 to your computer and use it in GitHub Desktop.
Product Enquiry form using WooCommerce and Contact Form 7: https://www.damiencarbery.com/2017/02/product-enquiry-form-using-woocommerce-and-contact-form-7/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: CF7 form to all products (after short description, with add_action) | |
Plugin URI: http://www.damiencarbery.com | |
Description: Append a Contact Form 7 form to the Short Description section of all Woocommerce products. | |
Author: Damien Carbery | |
Version: 0.1 | |
WC tested up to: 8.0.2 | |
*/ | |
// Add the CF7 form between the short description and the 'Add to cart' button. | |
add_action( 'woocommerce_single_product_summary', 'dcwd_add_cf7_form_after_single_excerpt', 25 ); | |
function dcwd_add_cf7_form_after_single_excerpt() { | |
echo do_shortcode('[contact-form-7 id="73" title="Contact form 1"]'); ; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: CF7 form to all products (after short description, with add_filter) | |
Plugin URI: http://www.damiencarbery.com | |
Description: Append a Contact Form 7 form to the Short Description section of all Woocommerce products. | |
Author: Damien Carbery | |
Version: 0.1 | |
WC tested up to: 8.0.2 | |
*/ | |
// Add the CF7 form between the short description and the 'Add to cart' button. | |
add_filter('woocommerce_short_description', 'dcwd_append_cf7_form_to_short_description'); | |
function dcwd_append_cf7_form_to_short_description( $short_description ) { | |
return $short_description . do_shortcode('[contact-form-7 id="73" title="Contact form 1"]'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: CF7 to product page | |
Plugin URI: https://www.damiencarbery.com/2018/06/customise-choose-an-option-dropdown-item/ | |
Description: Add a Contact Form 7 form to the product page. | |
Author: Damien Carbery | |
Version: 0.1 | |
WC tested up to: 8.0.2 | |
*/ | |
add_action( 'woocommerce_after_add_to_cart_button', 'dcwd_add_cf7_form_under_add_to_cart' ); | |
function dcwd_add_cf7_form_under_add_to_cart() { | |
// Add the hidden contact form. It will be displayed when the button is clicked. | |
echo '<div id="askinfo" style="display:none">' . do_shortcode( '[contact-form-7 id="73" title="Contact form 1"]' ) . '</div>'; | |
// Button to open the popup. | |
echo '<button><a href="#TB_inline?height=600&width=400&inlineId=askinfo" class="thickbox">Ask for Info</a></button>'; | |
// Add the thickbox JS and CSS for the popup. | |
add_thickbox(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[dynamic_hidden page-url "CF7_URL"] | |
[dynamic_hidden site-url "CF7_bloginfo show='url'"] | |
[dynamic_hidden post-id "CF7_get_post_var key='ID'"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>SKU<br /> | |
[dynamic_text product-sku "CF7_get_custom_field key='_sku'"]</p> | |
In the email: | |
SKU: [product-sku] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: CF7 to product page (specified categories) | |
Plugin URI: https://www.damiencarbery.com/2018/06/customise-choose-an-option-dropdown-item/ | |
Description: Add a Contact Form 7 form to the product page of products in specified categories only. | |
Author: Damien Carbery | |
Version: 0.1 | |
WC tested up to: 8.0.2 | |
*/ | |
add_action( 'woocommerce_after_add_to_cart_button', 'dcwd_add_cf7_form_under_add_to_cart' ); | |
function dcwd_add_cf7_form_under_add_to_cart() { | |
// Add the contact form for products in the tshirts category. | |
if ( has_term( array('tshirts', 'accessories' ), 'product_cat' ) ) { | |
echo do_shortcode( '[contact-form-7 id="73" title="Contact form 1"]' ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Page URL: [page-url] | |
Edit URL: [site-url]/wp-admin/post.php?post=[post-id]&action=edit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[contact-form-7 id="27" title="Product Enquiry"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<label>Product Name | |
[dynamic_text product-name "CF7_get_post_var key='title'"]</label> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: CF7 form to All Products | |
Plugin URI: http://www.damiencarbery.com | |
Description: Append a Contact Form 7 form to the Product Description section of all Woocommerce products. | |
Author: Damien Carbery | |
Version: 0.2 | |
WC tested up to: 8.0.2 | |
*/ | |
add_filter('the_content', 'dc_cf7_form_to_all_products'); | |
function dc_cf7_form_to_all_products($content) { | |
if ( class_exists( 'woocommerce' ) && is_product() && is_main_query() ) { // Check suggested by: https://pippinsplugins.com/playing-nice-with-the-content-filter/ | |
return $content . '[contact-form-7 id="8018" title="Product Enquiry"]'; | |
} | |
return $content; | |
} | |
// Ensure the Description tab is present as it is needed by the_content filter. | |
add_filter( 'woocommerce_product_tabs', 'dc_cf7_add_description_tab', 20 ); | |
function dc_cf7_add_description_tab( $tabs ) { | |
global $product, $post; | |
// Description tab - add if there is no post content (i.e. if the Description is empty) | |
// because woocommerce_default_product_tabs() in woocommerce/includes/wc-template-functions.php | |
// excludes it if the post content is empty. | |
if ( ! $post->post_content ) { | |
$tabs['description'] = array( | |
'title' => __( 'Description', 'woocommerce' ), | |
'priority' => 10, | |
'callback' => 'woocommerce_product_description_tab', | |
); | |
} | |
return $tabs; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('the_content', 'dc_cf7_form_to_all_products'); | |
function dc_cf7_form_to_all_products($content) { | |
if ( class_exists( 'woocommerce' ) && is_product() && is_main_query() ) { // Check suggested by: https://pippinsplugins.com/playing-nice-with-the-content-filter/ | |
global $post; | |
$product = wc_get_product($post); | |
// Only display the form when the product is in stock. | |
if ( $product->is_in_stock() ) { | |
return $content . '[contact-form-7 id="27" title="Product Enquiry"]'; | |
} | |
} | |
return $content; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: CF7 form to All Products | |
Plugin URI: http://www.damiencarbery.com | |
Description: Append a Contact Form 7 form to the Short Description section of all Woocommerce products. | |
Author: Damien Carbery | |
Version: 0.1 | |
WC tested up to: 8.0.2 | |
*/ | |
add_filter('woocommerce_short_description', 'dc_cf7_form_to_all_products'); | |
function dc_cf7_form_to_all_products($content) { | |
if ( class_exists( 'woocommerce' ) && is_product() && is_main_query() ) { // Check suggested by: https://pippinsplugins.com/playing-nice-with-the-content-filter/ | |
return $content . '[contact-form-7 id="27" title="Product Enquiry"]'; | |
} | |
return $content; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[03-Feb-2017 20:53:18 UTC] PHP Fatal error: Call to undefined function is_product() in /wp-content/plugins/wc-cf7-form-to-all-products.php on line 14 |
Can You tell me the way to redirect to the cart page through the button which I changed submit to Add to cart.
Can You tell me the way to redirect to the cart page through the button which I changed submit to Add to cart.
Redirect to cart is not hard - the CF7 docs show how to do it: https://contactform7.com/redirecting-to-another-url-after-submissions/
This redirect will not show the price. I think that you should use a variable product. CF7 is not a good solution for this.
Why do you not use a variable product?
OK, Thanks Now I will use variable product:)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much to answer me. Yes, I use Woo-Commerce on my site, I have been made form in contact form 7 below:
I want to redirect the form to the cart page with a price which shows in the total field. You can see my form, I've attached it.