PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.10
Booktics – Appointment Booking Calendar for Service Businesses v1.0.10
1.0.29 1.0.28 1.0.27 1.0.26 1.0.25 1.0.24 1.0.23 1.0.22 1.0.21 1.0.20 1.0.19 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.2 1.0.3 All 31 releases
booktics / core / order / order-hooks.php

order-hooks.php in Booktics – Appointment Booking Calendar for Service Businesses 1.0.10, at core/order/order-hooks.php

63 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Booktics\Order;
4
5 use Booktics\Contracts\Hookable_Service_Contract;
6 use Booktics\Models\Appointment_Model;
7
8 class Order_Hooks implements Hookable_Service_Contract {
9
10 /**
11 * Register the hooks for the order model.
12 *
13 * @return void
14 */
15 public function register() {
16 add_action( 'booktics_order_filters', [
17 $this,
18 'team_member_order_filters'
19 ] );
20 }
21
22 /**
23 * Filter order conditions based on the current user's role.
24 *
25 * @param array $conditions The order conditions.
26 *
27 * @return array The filtered order conditions.
28 */
29 public function team_member_order_filters( $conditions ) {
30 $current_user = wp_get_current_user();
31 $roles = $current_user->roles;
32
33 if ( in_array( 'administrator', $roles, true ) ) {
34 return $conditions;
35 }
36
37 if ( in_array( 'booktics_team_member', $roles, true ) ) {
38 $order_ids = $this->get_order_ids();
39 $conditions['id'] = [ 'in', $order_ids ];
40 }
41
42 return $conditions;
43 }
44
45 /**
46 * Get order ids for a date range
47 *
48 * @param array $dates
49 *
50 * @return array
51 */
52 private function get_order_ids() {
53 $order_ids = ['null'];
54 $args = [];
55 $args = apply_filters( 'booktics_appointment_args', $args );
56 $appointments = ( new Appointment_Model() )->all( $args );
57 foreach ( $appointments as $appointment ) {
58 $order_ids[] = $appointment->order_id;
59 }
60
61 return $order_ids;
62 }
63 }