Do you want to pre-populate and hide the name and email fields, or just pre-populate them?
Also, if you require that customers are logged in to submit a review, then you can hide the name and email field (using the hide option on the shortcode of block) and Site reviews will automatically use the email and display name of the logged in user.
-
This reply was modified 4 years, 4 months ago by
Gemini Labs.
Thread Starter
rapsli
(@rapsli)
I think to force the user to login would make it too hard to submit a review. Prepopulate would actually just be enough, what would be even better would be to connect it with an order, like
mysite.com/site-review?order=234234&[email protected]
The form would then be prepopulated and the combination of order and e-mail would give some kind of security.
Here is an example of pre-populating the email field based on the email value of the URL Query: https://pastebin.com/UDBQeTzM
You could extend this example to pre-populate the name field in the same way.
Auto-assigning the review to the product(s) in the order would be a little more work. You would first need to get the product IDs from the order number, and then set the value of the hidden assigned_posts field with those values. For example, if you are using Woocommerce then this would look something like this:
$order = wc_get_order(filter_input(INPUT_GET, 'order'));
if ($order) {
$productIds = [];
foreach ($order->get_items() as $item) {
$productIds[] = $item->get_product_id();
}
$fields['assigned_posts']['value'] = implode(',', array_filter($productIds));
}