Development ideas for WOOCommerce to evaluate and score after purchase

Woocommerce Mall Wordpress&woocommerce development record WordPress Technology Blog Wp application technology

The scoring and evaluation system of woocommerce

In the process of developing the woocommerce project in the WEB theme park, we found that the evaluation and scoring system of woocommerce is directly modified using wordpress comments, that is, all settings are inherited from wordpress comments.

In this way, we can only set the permissions that users can evaluate after logging in, but cannot set the permissions that users can evaluate after purchasing.

In normal e-commerce websites, we can score goods only after we have purchased the goods and received the goods. However, this scoring mechanism of Woocommerce allows everyone to evaluate, even though it will mark that those people have already purchased the goods (display a sign to verify the user).

So, what if we want to let users evaluate after purchase like most e-commerce websites?

Next, we will explain some of our ideas and basic code analysis in the development process of the woocommerce project. If you are also developing the woocommerce project, the following ideas may also be helpful to you.

 

WOOCommerce's score input system modification idea

 

Woocommerce's scoring system is modified directly using wordpress, so the comment input box will appear directly at the bottom of the comment, and anyone can comment directly on the product page:

 Development ideas for WOOCommerce to evaluate and score after purchase

 

Therefore, it is inappropriate for us to put the comment box here, because we hope that Woocommerce's scoring system is the same as most e-commerce websites, and each order of goods can be evaluated once, and the score has been obtained.

Therefore, our idea is to put the score into the order page and judge whether the order status is "Completed" or "Shipped". We also need to judge whether it has been evaluated. If it has been evaluated, the comment input box will not be displayed.

As shown in the following figure, if there are 2 items in the order and the second item has been evaluated, the evaluation will be expanded to display our scores and evaluations, while if the first item has no evaluation, the status of the input box will be displayed:

 Development ideas for WOOCommerce to evaluate and score after purchase

 

Finally, we will delete the comment box on the product details page, so that only the users who have purchased can give a score. However, this comment box can also make a judgment. If the administrator and editor log in, it will not be deleted, and it will be reserved for the product to be reviewed.

 

Basic code sharing scored by woocommerce after purchase

First, we need to add a comment field. First, we need to combine the order number and product ID into a specific number, which will identify the goods of the order as unique.

Here I add the comment field of "orderid" and guarantee that the comment will be saved later.

add_action('wp_insert_comment','wp_insert_order',10,2);
function wp_insert_order($comment_ID,$commmentdata) {
$orderid = isset($_POST['orderid']) ? $_ POST['orderid'] : false;
update_comment_meta($comment_ID,'orderid',$orderid);
}

Then we write a judgment function, whose logic is to check all the comments of the current user. If a comment has the "orderid" comment field added above, it will return the comment with this field, if not, it will return null:

Function file download: woo_order_comment_yes

The above function helps us filter the goods in the order. The following function determines whether to output a comment box or an existing comment through the above judgment:

Function file download: woo_order_comment

Finally, we will add this function on the order page and output it, specifically in the WOOCommerce template (the special theme will have a WOOCommerce folder, which contains WOOCommerce templates)

Find order/order-details-item.php

Output a tr table under product total

<td>  <? php woo_order_comment($item['product_id'],$order->id,'btttom'); ?></ td>

This completes the output of comments and comment boxes in our order.

Then make a judgment to hide the comment box on the product page, and you are finished. This basic code needs to be further detailed to be more beautiful and adaptable.

Finally, I hope this idea and basic code will help you.

 

Previous:

Next:

Expand more