May 31, 2026
Uncategorized
WooCommerce定制开发案例:预约挂号系统完整实现
项目背景
客户是一家医疗诊所,希望基于WooCommerce开发在线预约挂号系统。需求包括:选择医生、选择时间段、支付挂号费、发送提醒通知等。
这是一个典型的服务预约类WooCommerce二次开发项目,涉及复杂的日程管理和支付集成。
客户痛点
- 人工挂号效率低:电话挂号需要人工记录,容易出错
- 时间冲突:无法实时查看医生已预约时间段
- 支付分离:挂号和支付分开,容易跑单
- 提醒缺失:患者容易忘记预约时间
- 数据分析难:无法统计医生工作量、患者来源等数据
我们的解决方案
1. 医生与时间段管理
- 创建医生自定义文章类型(CPT)
- 为每个医生设置可预约时间段(如周一上午9-12点)
- 使用Advanced Custom Fields(ACF)插件管理医生信息
- 使用WordPress元数据存储已预约时间段
2. 预约选择界面
- 在产品页选择医生、日期、时间段
- 使用Ajax实时检查时间段是否已被预约
- 使用jQuery UI Datepicker实现日期选择
- 使用WooCommerce产品附加组件插件添加预约选项
3. 支付集成
- 将挂号费设置为WooCommerce产品
- 预约时自动将挂号费加入购物车
- 支付成功后,自动锁定时间段
- 使用WooCommerce支付网关(微信支付、支付宝、PayPal等)
4. 提醒通知系统
- 使用WordPress Cron定时任务
- 在预约前24小时、1小时自动发送提醒短信/邮件
- 使用Twilio API发送短信提醒
- 使用WooCommerce邮件系统发送邮件提醒
5. 后台管理系统
- 使用WordPress Dashboard Widgets展示今日预约
- 医生可查看自己的预约列表
- 管理员可导出预约数据(CSV、Excel)
- 使用Chart.js绘制预约量趋势图
技术实现细节
核心代码片段:
// 检查时间段是否可用add_action('wp_ajax_check_time_slot_availability', 'check_time_slot_availability');function check_time_slot_availability() { $doctor_id = intval($_POST['doctor_id']); $date = sanitize_text_field($_POST['date']); $time_slot = sanitize_text_field($_POST['time_slot']); // 查询已被预约的时间段 $booked_slots = get_post_meta($doctor_id, '_booked_slots', true); if (!is_array($booked_slots)) { $booked_slots = []; } // 检查当前时间段是否已被预约 if (in_array($date . '_' . $time_slot, $booked_slots)) { wp_die(json_encode(['available' => false])); } else { wp_die(json_encode(['available' => true])); }}// 预约成功后锁定时间段add_action('woocommerce_payment_complete', 'lock_appointment_time_slot');function lock_appointment_time_slot($order_id) { $order = wc_get_order($order_id); foreach ($order->get_items() as $item) { $doctor_id = wc_get_order_item_meta($item->get_id(), '_doctor_id', true); $appointment_date = wc_get_order_item_meta($item->get_id(), '_appointment_date', true); $time_slot = wc_get_order_item_meta($item->get_id(), '_time_slot', true); if ($doctor_id && $appointment_date && $time_slot) { // 锁定时间段 $booked_slots = get_post_meta($doctor_id, '_booked_slots', true); if (!is_array($booked_slots)) { $booked_slots = []; } $booked_slots[] = $appointment_date . '_' . $time_slot; update_post_meta($doctor_id, '_booked_slots', $booked_slots); } }}// 预约提醒(Cron任务)add_action('send_appointment_reminders', 'send_appointment_reminders');function send_appointment_reminders() { $args = [ 'post_type' => 'appointment', 'meta_query' => [ [ 'key' => '_appointment_time', 'value' => [time(), time() + 86400], // 24小时内的预约 'compare' => 'BETWEEN', ], [ 'key' => '_reminder_sent', 'compare' => 'NOT EXISTS', ], ], ]; $query = new WP_Query($args); while ($query->have_posts()) { $query->the_post(); $appointment_id = get_the_ID(); $patient_phone = get_post_meta($appointment_id, '_patient_phone', true); $appointment_time = get_post_meta($appointment_id, '_appointment_time', true); // 发送短信提醒 $message = '尊敬的客户,您明天' . date('H:i', $appointment_time) . '有预约,请准时到达。'; send_sms_via_twilio($patient_phone, $message); // 标记提醒已发送 update_post_meta($appointment_id, '_reminder_sent', 'yes'); }}
项目成果
- 挂号效率提升:在线预约上线后,人工挂号时间减少每天3小时
- 预约冲突率下降:实时检查可用时间段,冲突率从5%降到0%
- 支付成功率提升:挂号费在线支付,支付成功率达到98%
- 提醒效果显著:短信提醒上线后,患者爽约率从15%降到5%
- 数据可视化:后台可查看预约量趋势、医生工作量等数据,管理效率提升50%
项目周期与报价
- 开发周期:35天(需求分析7天 + 开发25天 + 测试3天)
- 项目报价:¥20,000(含需求分析、开发、测试、上线、2个月维护)
- 技术方案:WordPress + WooCommerce + 自定义插件 + Twilio SMS API
结语
这个案例展示了WooCommerce在服务预约领域的强大扩展能力。通过二次开发,WooCommerce不仅可以做电商,还可以做医疗挂号、美容预约、咨询预约等服务类业务。
如果您也需要基于WooCommerce开发预约挂号系统,或者需要定制其他WooCommerce功能,请联系我们!我们拥有丰富的WooCommerce二次开发经验,可以为您提供从需求分析、方案设计到开发上线的全流程服务。
服务内容包括:
- WooCommerce功能定制开发
- 服务预约系统开发
- 支付接口对接
- 短信/邮件提醒集成
- 数据报表后台开发
立即联系我们,获取免费技术方案和报价!