GBO Posted December 20, 2023 Share Posted December 20, 2023 Hello This forum has been a great help in the past. I have another query. I'm looking to add a contact form to appear under the contents of the WooCommerce Category pages only - not to appear in the product pages. I'm using the following code to display the form: add_action( 'woocommerce_after_main_content', function(){ // Title $header = "<br><b>Contact Us</b><br>"; // Message $text = "<p>Please do not hesitate to contact us with queries you may have</p><br>"; // WPForms shortcode $wpforms_shortcode = do_shortcode('[wpforms id="1385"]'); // Output combined message and form echo ' ' . $header .' ' . $text .' ' . $wpforms_shortcode .' '; }, 9 ); The result can be viewed here: https://www.offershubdirect.com/product-category/parts-services/ However, using the above code also makes the form appear at the bottom of the product pages (https://www.offershubdirect.com/product/2370-9085-terex-pegson-1412-blow-bar-hammers-chrome/) - no surprise here. How do I prevent the form from appearing on the product pages? Any help or guidance is appreciated. Gary Quote Link to comment https://forums.phpfreaks.com/topic/317556-adding-a-short-code-form-in-woocommerce-category-pages-only/ Share on other sites More sharing options...
Solution maxxd Posted December 20, 2023 Solution Share Posted December 20, 2023 It's been a long time since I've touched WP, but as I remember it right now you're using a global action - it fires on every page. You can either override the specific templates you're looking to add the form to, or check the template name and conditionally output the form. Quote Link to comment https://forums.phpfreaks.com/topic/317556-adding-a-short-code-form-in-woocommerce-category-pages-only/#findComment-1613691 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.