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); function test_review_submission() { // Sample data to simulate form submission $form_name = 'Review Form'; $raw_fields = [ 'your_name' => ['value' => 'Test User'], 'your_email' => ['value' => 'test@example.com'], 'your_review' => ['value' => 'This is a test review.'] ]; $record = new stdClass(); $record->get_form_settings = function($setting) use ($form_name) { return $form_name; }; $record->get_fields = function() use ($raw_fields) { return $raw_fields; }; // Simulate form submission do_action('elementor_pro/forms/new_record', $record, null); } add_action('init', 'test_review_submission');
Skip to content