// مرحله 3: Ajax برای دریافت و درج کامنت add_action('wp_ajax_honey_generate_comment', 'honey_ajax_generate_comment'); function honey_ajax_generate_comment() { $product_id = intval($_POST['product_id']); $gender = sanitize_text_field($_POST['gender']); $audience = sanitize_text_field($_POST['audience']); $tone = sanitize_text_field($_POST['tone']); $prompt = "لطفا یک نظر کاربر برای محصول عسلی با در نظر گرفتن ویژگی‌های زیر تولید کن: - جنسیت: $gender - مخاطب: $audience - لحن: $tone لطفاً نظر را به زبان فارسی بنویس."; $comment = honey_call_openai_api($prompt); if ($comment) { wp_send_json_success(['comment' => $comment]); } else { wp_send_json_error(); } } add_action('wp_ajax_honey_insert_comment', 'honey_ajax_insert_comment'); function honey_ajax_insert_comment() { $product_id = intval($_POST['product_id']); $comment = sanitize_textarea_field($_POST['comment']); $author = 'کاربر تست'; $author_email = 'test@example.com'; $commentdata = [ 'comment_post_ID' => $product_id, 'comment_content' => $comment, 'comment_author' => $author, 'comment_author_email' => $author_email, 'comment_approved' => 1, ]; $inserted = wp_insert_comment($commentdata); if ($inserted) { wp_send_json_success(); } else { wp_send_json_error(); } }
Fatal error: Uncaught Error: Call to undefined function wc_get_products() in /home/asalplus/public_html/wp-content/plugins/honey-comments/admin-page.php:6 Stack trace: #0 /home/asalplus/public_html/wp-content/plugins/honey-comments/honey-comments.php(21): require_once() #1 /home/asalplus/public_html/wp-settings.php(545): include_once('/home/asalplus/...') #2 /home/asalplus/public_html/wp-config.php(118): require_once('/home/asalplus/...') #3 /home/asalplus/public_html/wp-load.php(50): require_once('/home/asalplus/...') #4 /home/asalplus/public_html/wp-blog-header.php(13): require_once('/home/asalplus/...') #5 /home/asalplus/public_html/index.php(17): require('/home/asalplus/...') #6 {main} thrown in /home/asalplus/public_html/wp-content/plugins/honey-comments/admin-page.php on line 6