php - 我可以编辑 Amelia wordpress 预订系统以在不预订的情况下创建新客户吗?
问题描述
需要我的客户能够使用与他们预订时相同的详细信息登录网站,因为我可以在 amelia 中创建一个客户,将自身添加到默认的 wordpress 用户列表中,但是当我创建一个具有 amelia 客户角色的 wordpress 用户时不转移到阿米莉亚。
不知道这是否有帮助,但在插件 php.ini 中找到了这个。
<?php
namespace AmeliaBooking\Domain\Factory\User;
use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
use AmeliaBooking\Domain\Entity\User\Customer;
use AmeliaBooking\Domain\Entity\User\Manager;
use AmeliaBooking\Domain\Entity\User\Admin;
use AmeliaBooking\Domain\Entity\User\Provider;
use AmeliaBooking\Domain\Factory\Bookable\Service\ServiceFactory;
use AmeliaBooking\Domain\Factory\Google\GoogleCalendarFactory;
use AmeliaBooking\Domain\Factory\Outlook\OutlookCalendarFactory;
use AmeliaBooking\Domain\Factory\Schedule\PeriodServiceFactory;
use AmeliaBooking\Domain\Factory\Schedule\SpecialDayFactory;
use AmeliaBooking\Domain\Factory\Schedule\SpecialDayPeriodFactory;
use AmeliaBooking\Domain\Factory\Schedule\SpecialDayPeriodServiceFactory;
use AmeliaBooking\Domain\ValueObjects\DateTime\Birthday;
use AmeliaBooking\Domain\ValueObjects\Gender;
use AmeliaBooking\Domain\ValueObjects\Json;
use AmeliaBooking\Domain\ValueObjects\String\Password;
use AmeliaBooking\Domain\ValueObjects\String\Status;
use AmeliaBooking\Domain\ValueObjects\Picture;
use AmeliaBooking\Domain\ValueObjects\String\Description;
use AmeliaBooking\Domain\ValueObjects\String\Email;
use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
use AmeliaBooking\Domain\ValueObjects\String\Name;
use AmeliaBooking\Domain\ValueObjects\String\Phone;
use AmeliaBooking\Domain\Collection\Collection;
use AmeliaBooking\Domain\Factory\Schedule\DayOffFactory;
use AmeliaBooking\Domain\Factory\Schedule\TimeOutFactory;
use AmeliaBooking\Domain\Factory\Schedule\PeriodFactory;
use AmeliaBooking\Domain\Factory\Schedule\WeekDayFactory;
/**
* Class UserFactory
*
* @package AmeliaBooking\Domain\Factory\User
*/
class UserFactory
{
/**
* @param $data
*
* @return Admin|Customer|Manager|Provider
* @throws InvalidArgumentException
*/
public static function create($data)
{
if (!isset($data['type'])) {
$data['type'] = 'customer';
}
switch ($data['type']) {
case 'admin':
$user = new Admin(
new Name($data['firstName']),
new Name($data['lastName']),
new Email($data['email'])
);
break;
case 'provider':
$weekDayList = [];
$dayOffList = [];
$specialDayList = [];
$serviceList = [];
$appointmentList = [];
if (isset($data['weekDayList'])) {
foreach ((array)$data['weekDayList'] as $weekDay) {
$timeOutList = [];
if (isset($weekDay['timeOutList'])) {
foreach ((array)$weekDay['timeOutList'] as $timeOut) {
$timeOutList[] = TimeOutFactory::create($timeOut);
}
$weekDay['timeOutList'] = $timeOutList;
}
$periodList = [];
if (isset($weekDay['periodList'])) {
foreach ((array)$weekDay['periodList'] as $period) {
$periodServiceList = [];
if (isset($period['periodServiceList'])) {
foreach ((array)$period['periodServiceList'] as $periodService) {
$periodServiceList[] = PeriodServiceFactory::create($periodService);
}
}
$period['periodServiceList'] = $periodServiceList;
$periodList[] = PeriodFactory::create($period);
}
$weekDay['periodList'] = $periodList;
}
$weekDayList[] = WeekDayFactory::create($weekDay);
}
}
if (isset($data['specialDayList'])) {
foreach ((array)$data['specialDayList'] as $specialDay) {
$periodList = [];
if (isset($specialDay['periodList'])) {
foreach ((array)$specialDay['periodList'] as $period) {
$periodServiceList = [];
if (isset($period['periodServiceList'])) {
foreach ((array)$period['periodServiceList'] as $periodService) {
$periodServiceList[] = SpecialDayPeriodServiceFactory::create($periodService);
}
}
$period['periodServiceList'] = $periodServiceList;
$periodList[] = SpecialDayPeriodFactory::create($period);
}
$specialDay['periodList'] = $periodList;
}
$specialDayList[] = SpecialDayFactory::create($specialDay);
}
}
if (isset($data['dayOffList'])) {
foreach ((array)$data['dayOffList'] as $dayOff) {
$dayOffList[] = DayOffFactory::create($dayOff);
}
}
if (isset($data['serviceList'])) {
foreach ((array)$data['serviceList'] as $service) {
$serviceList[$service['id']] = ServiceFactory::create($service);
}
}
$user = new Provider(
new Name($data['firstName']),
new Name($data['lastName']),
new Email($data['email']),
new Phone(isset($data['phone']) ? $data['phone'] : null),
new Collection($weekDayList),
new Collection($serviceList),
new Collection($dayOffList),
new Collection($specialDayList),
new Collection($appointmentList)
);
if (!empty($data['password'])) {
$user->setPassword(new Password($data['password']));
}
if (!empty($data['locationId'])) {
$user->setLocationId(new Id($data['locationId']));
}
if (!empty($data['googleCalendar']) && isset($data['googleCalendar']['token'])) {
$user->setGoogleCalendar(GoogleCalendarFactory::create($data['googleCalendar']));
}
if (!empty($data['outlookCalendar']) && isset($data['outlookCalendar']['token'])) {
$user->setOutlookCalendar(OutlookCalendarFactory::create($data['outlookCalendar']));
}
if (!empty($data['zoomUserId'])) {
$user->setZoomUserId(new Name($data['zoomUserId']));
}
if (!empty($data['id'])) {
$user->setId(new Id($data['id']));
}
break;
case 'manager':
$user = new Manager(
new Name($data['firstName']),
new Name($data['lastName']),
new Email($data['email'])
);
break;
case 'customer':
default:
$user = new Customer(
new Name($data['firstName']),
new Name($data['lastName']),
new Email($data['email'] ?: null),
new Phone(!empty($data['phone']) ? $data['phone'] : null),
new Gender(!empty($data['gender']) ? strtolower($data['gender']) : null)
);
break;
}
if (!empty($data['countryPhoneIso'])) {
$user->setCountryPhoneIso(new Name($data['countryPhoneIso']));
}
if (!empty($data['birthday'])) {
if (is_string($data['birthday'])) {
$user->setBirthday(new Birthday(\DateTime::createFromFormat('Y-m-d', $data['birthday'])));
} else {
$user->setBirthday(new Birthday($data['birthday']));
}
}
if (!empty($data['id'])) {
$user->setId(new Id($data['id']));
}
if (!empty($data['externalId'])) {
$user->setExternalId(new Id($data['externalId']));
}
if (!empty($data['pictureFullPath']) && !empty($data['pictureThumbPath'])) {
$user->setPicture(new Picture($data['pictureFullPath'], $data['pictureThumbPath']));
}
if (!empty($data['status'])) {
$user->setStatus(new Status($data['status']));
}
if (!empty($data['note'])) {
$user->setNote(new Description($data['note']));
}
return $user;
}
}
解决方案
尝试这个。在支持论坛上找到它。
add_action( 'user_register', 'custom_amelia_registration_save', 10, 1 );
function custom_amelia_registration_save($user_id) {
global $wpdb;
$wpUser = get_user_by('ID', $user_id);
$ameliaUserId = $wpdb->get_col(
"SELECT id FROM wp_amelia_users WHERE email = '{$wpUser->user_email}'"
);
if (!$ameliaUserId && in_array('wpamelia-customer', $wpUser->roles)) {
$ameliaUserFirstName = $wpUser->user_first_name ?: $wpUser->user_nicename;
$ameliaUserLastName = $wpUser->user_last_name ?: $wpUser->user_nicename;
$wpdb->query("
INSERT INTO wp_amelia_users
(
type,
status,
externalId,
firstName,
lastName,
email
) VALUES (
'customer',
'visible',
{$user_id},
'{$ameliaUserFirstName}',
'{$ameliaUserLastName}',
'{$wpUser->user_email}'
)
");
}
}
推荐阅读
- video - ffmepg - 当我运行第二个实例时,第一个停止
- reactjs - ReactJS 重新渲染太多。React 限制渲染次数以防止无限循环
- java - 使用轮廓检测不完整/破圆
- mysql - 如何在 MySQL 中加入 3 个表
- c++ - 由于重定位错误,编译失败
- vue.js - Vue.js - 从孙插槽组件发射没有将 $emit 事件冒泡到父级
- reactjs - 如何从反应原生的正常功能中获取上下文值?(没有 useContext 或类组件)
- c# - 如何访问 C# 中的继承方法?
- algorithm - 基于球员得分的比赛调度算法
- reactjs - 出现错误**错误:无效的挂钩调用。钩子只能在函数组件的主体内部调用。**