Allow site admin or Amelia Employees/Managers create appointments without making a payment.
I recently started using Amelia booking plugin and needed a way to allow the site admin create appointments without making a payment, while requiring that customers pay (to discourage . With a bit of a hack I was able to achive this.
Unlike WordPress core and WooCommerce Amelia does not have many
apply_filters() calls (28 vs over 2200 in WordPress!) or
do_action() calls (7 vs over 1000 in WordPress) to allow developers interact with the plugin code. So, when I needed to modify a setting value I had to use a WordPress filter instead of an Amelia one.
When get_option() is called there are 3 filters that can be used to modify the returned data. I chose to use the ‘
option_$option‘ one so that it would only run for a specific Amelia option value, ‘
amelia_settings‘ is a long JSON string. For speed I do a str_replace() of the
onSite setting changing
false) as I felt calling json_decode()/json_encode() would be overkill as the change was simple.
Next up is to check whether the user is an admin or an Amelia Employee or Manager (new roles created by the plugin). For the admin I check whether they have the ‘
manage_options‘ capability, and for the Amelia Employee I check ‘
amelia_delete_events‘ (because Amelia Manager also has this capability).
Initially I used a
is_user_logged_in() check but customers can create accounts (which get Amelia Customer role) so I had to change this to capability checks.
Enable On-site payments
To use the code below you must enable On-site payments for each service. That said, the code could be modified to from the current disabling on-site payments for customers to enabling them for only admins/employees/managers. The downside is that there might be services where on-site payments should never be permitted and the current method retains that control.
When a user is logged in they only see the Stripe form.
Admins and Amelia Employees & Managers can choose an On-site or Stripe option.