add_action('elementor_pro/forms/new_record', function($record, $handler) { $form_name = $record->get_form_settings('form_name'); // Log the form name to verify the form trigger error_log('Form Name: ' . $form_name); if ('Review Form' !== $form_name) { error_log('Form Name does not match. Exiting...'); return; } $raw_fields = $record->get_fields(); $name = sanitize_text_field($raw_fields['your_name']['value']); $email = sanitize_email($raw_fields['your_email']['value']); $review = sanitize_textarea_field($raw_fields['your_review']['value']); // Log field values for debugging error_log('Name: ' . $name); error_log('Email: ' . $email); error_log('Review: ' . $review); // Add Review to WooCommerce Reviews Section (without product association) $comment_data = [ 'comment_author' => $name, 'comment_author_email' => $email, 'comment_content' => $review, 'comment_type' => 'review', 'comment_approved' => 1, 'comment_post_ID' => 0 // Not associated with any product ]; $result = wp_insert_comment($comment_data); // Log the result if ($result) { error_log('Review added successfully. Comment ID: ' . $result); } else { error_log('Failed to add review.'); } }, 10, 2);
Skip to content