Add A Comment Form / Q&A Form To WooCommerce Product Page

Outline

    Original Post

    Add A Comment Form / Q&A Form To WooCommerce Product Page


    By default, there is a review form on WooCommerce product page, but customers can’t reply and discuss. If you want to add a comment form or question/answer form, you may need to install some plugins like WooDiscuz. However, we can hack comment template to achieve this without any plugin.

    Actually, the review form in WooCommerce and the comment form in WordPress post are the same thing, but with different templates. So what we will do is to override the WooCommerce template.

    Step 1. Copy Template To Theme Directory

    Go the the plugin folder, the path as below, and copy the single-product-reviews.php.

    /wp-content/plugins/woocommerce/templates/single-product-reviews.php

    Paste the file to your theme directory:

    /wp-content/themes/[Theme Name]/woocommerce

    In this way, we can override the default templates of WooCommerce without modifying the original files. It’s the best practice to customize your WooCommerce theme.

    Step 2. Modify The Code

    Add a line in the template, which will display the WordPress comment form. And you don’t need the original code anymore.

    require get_template_directory() . ‘/comments.php’;

    The new product review template will be like this:

    <?php
    /**
     * Display single product reviews (comments)
     *
     * This template can be overridden by copying it to yourtheme/woocommerce/single-product-reviews.php.
     *
     * HOWEVER, on occasion WooCommerce will need to update template files and you
     * (the theme developer) will need to copy the new files to your theme to
     * maintain compatibility. We try to do this as little as possible, but it does
     * happen. When this occurs the version of the template file will be bumped and
     * the readme will list any important changes.
     *
     * @see     https://docs.woocommerce.com/document/template-structure/
     * @package WooCommerce/Templates
     * @version 4.3.0
     */
    defined( 'ABSPATH' ) || exit;
    global $product;
    if ( ! comments_open() ) {
    	return;
    }
    require get_template_directory() . '/comments.php';
    ?>

    Disadvantage

    It’s a perfect and easy way to add a comment form to your product page. However, it means you will lose the feature of product review. So it depends on your needs.



    Related Posts

    Aron

    A data scientist working in a retail company, with experience in web design and marketing. Recently dives into cryptocurrency and quantitative investing.

    facebook telegram

    8 comments

    1. Matt

      Brother. You just saved me a weeks work… thank you

    2. Masud Rana

      It worked. Thank you so much. I must appreciate it. 🙂

    3. Masud Rana

      It worked. Thank you so must. I must appreciate it. 🙂

    4. Evelyn Richardson

      You have presented your article in a really beautiful way. I have read the full article and I will suggest this article for newcomers. Thank you very much.

    5. beautifully

      If you ever find yourself looking at the Instagram and Facebook post of others comparing your life to theirs. You are not alone I think we all have done this before. However remember that there is no more perfect life than the one you have. There is no one like you in this world. Learn to love what what makes you unique and special.

    6. 대전출장

      Pretty section of content. I just stumbled upon your
      website and in accession capital to assert that I get in fact enjoyed account your blog posts.
      Any way I’ll be subscribing to your augment and even I achievement you access consistently rapidly.

    7. 부산달리기

      Wonderful beat ! I wish to apprentice whilst you amend your web site, how
      can i subscribe for a weblog web site? The account helped me a applicable deal.

      I have been tiny bit acquainted of this your broadcast offered brilliant transparent
      idea

    8. 부산유흥사이트

      Hello! Quick question that’s entirely off topic.
      Do you know how to make your site mobile friendly? My website looks weird when viewing from my iphone.
      I’m trying to find a template or plugin that might be able to fix this issue.
      If you have any recommendations, please share. Thank you!

    Leave a Reply

    • Required fields are market * .
    • Your email address will not be published.
    • Please ensure your email address is correct, then you will get a notification once a new comment reply.

    Your email address will not be published.