Bạn muốn lưu trữ thông tin khách hàng từ contact fom 7 lên google google sheet giúp quản lý tốt hơn và dễ chăm sóc khách hàng hơn.có thể làm theo các bước sau nhé:
✅ Bước 1: Tạo Google Sheet
-
Vào Google Drive → Tạo mới → Google Sheet → Đặt tên:
Danh sách đăng ký
-
Đổi tên sheet/tab (nằm dưới cùng) thành:
dangkytuvan
-
Tạo dòng tiêu đề (tuỳ chọn):
Thời gian | Họ tên | Email | Số điện thoại
✅ Bước 2: Tạo Google Apps Script
-
Trong Google Sheet → Chọn menu Tiện ích mở rộng → Apps Script
-
Xóa nội dung mặc định, dán đoạn mã sau:
</p> <div>function doPost(e) {</div> <div> const sheet = SpreadsheetApp.openById("1S1jKz-BXoQ8KTSDTNJKKqOtPkcEvL3rVabsbI0Zx-uI")</div> <div> .getSheetByName("dangkytuvan");</div> <div></div> <div> if (!sheet) {</div> <div> return ContentService.createTextOutput("Không tìm thấy sheet 'dangkytuvan'");</div> <div> }</div> <div></div> <div> const data = e.parameter;</div> <div></div> <div> sheet.appendRow([</div> <div> new Date(),</div> <div> data["text-294"] || '',</div> <div> data["email-108"] || '',</div> <div> data["tel-718"] || ''</div> <div> ]);</div> <div></div> <div> return ContentService.createTextOutput("Success");</div> <div>}</div> <p data-start="692" data-end="731">
✅ Trong đó:
-
text-294
= họ tên -
email-108
= email -
tel-718
= số điện thoại
✅ Trong đó:
text-294 = họ tên
email-108 = email
tel-718 = số điện thoại
https://script.google.com/macros/s/AKfycb.../exec
✅ Bước 4: Tạo Contact Form 7
Trong WordPress → Contact Form 7 → Tạo form mới hoặc sửa form cũ, dùng cấu trúc:
plaintext
Copy
Edit
Thêm đoạn sau vào file functions.php của theme (hoặc plugin riêng):
add_action('wpcf7_mail_sent', 'gui_dulieu_google_sheets_cf7'); function gui_dulieu_google_sheets_cf7($contact_form) { $submission = WPCF7_Submission::get_instance(); if (!$submission) return; $data = $submission->get_posted_data(); $payload = [ 'text-294' => sanitize_text_field($data['text-294'] ?? ''), 'email-108' => sanitize_email($data['email-108'] ?? ''), 'tel-718' => sanitize_text_field($data['tel-718'] ?? '') ]; wp_remote_post('https://script.google.com/macros/s/AKfycb.../exec', [ 'method' => 'POST', 'body' => $payload, 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'] ]); }
📌 Thay thế đường link https://script.google.com/macros/s/… bằng URL Web App của bạn.