search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

Add A Comment Form / Q&A Form To WooCommerce Product Page | ARON HACK 亞倫害的

目錄

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:

 

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.

Content Protection by DMCA.com
A
Aron

Data analyst, but building WordPress websites, having experience in digital marketing. Recently dives into fighting and Python quantitative investment.



熱門推薦

本文由 aronhackcom 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦