By default, a client can review a store item after an order with that item is delivered. Your plugin can change this, for example to allow reviews only while the client's license is active.
The filter
Use the app_filter_store_item_review_permission filter. It runs when the review form is shown and when a review is saved or edited.
app_hooks()->add_filter('app_filter_store_item_review_permission', function ($permission, $context) {
//$permission: array("allowed" => true or false, "message" => "...", "order_id" => ...)
//$context: item_info, user, client_id, delivered_order_ids, review_info
if ($permission["allowed"] && !my_plugin_has_active_license($context["client_id"], $context["item_info"]->id)) {
return array("allowed" => false, "message" => "Your license has expired.");
}
return $permission;
}, 10, 2);
What you can return
- allowed: true to show the review form and save the review, false to block it.
- message: shown to the client when the review is blocked.
- order_id: the order saved with the review. Keep the default unless the review belongs to another order.
You can also allow clients who have no delivered order, for example when they bought a license outside RISE. Only clients who can open the store can write reviews.
review_info is the client's existing review, or null for a new one. Use it if you want to allow editing an old review after the license ends.
Refunded items
An order item closed with the app_filter_store_order_item_delivery_available filter doesn't count as a delivered order. So after a refund, the client can't write a new review of that item.
To remove the review the client already wrote, call this after the refund:
\App\Libraries\Store_feedback::delete_review_of_order_item($order_item_id);
It deletes the client's review of the item. The review stays if the client has another delivered order of the same item. It returns the number of deleted reviews.