Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Replace Woocommerce Product Enquiry Form with Ninja Form
// Include a Ninja Forms form in a product page. Different forms for simple and variable products.
add_filter( 'the_content', 'ninja_product_enquiry_form' );
function ninja_product_enquiry_form( $content ) {
if ( class_exists( 'woocommerce' ) && is_product() && is_main_query() ) {
global $product;
if ( 'simple' == $product->get_type() ) {
ob_start();
Ninja_Forms()->display( 3 ); // Equivalent to shortcode: [ninja_form id=3]
return $content . ob_get_clean();
}
if ( 'variable' == $product->get_type() ) {
ob_start();
Ninja_Forms()->display( 3 ); // Equivalent to shortcode: [ninja_form id=3]
return $content . ob_get_clean();
}
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment