Jump to content

Adding a short code form in WooCommerce Category pages only


Go to solution Solved by maxxd,

Recommended Posts

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

 

 

php contact form.PNG

php contact form2.PNG

  • Solution

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.