PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.19
Booktics – Appointment Booking Calendar for Service Businesses v1.0.19
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 1.0.4 1.0.5 1.0.6 1.0.7 All 27 releases
booktics / core / order / order-hooks.php

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

65 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 if ( ! defined( 'ABSPATH' ) ) exit;
6
7 use Booktics\Contracts\Hookable_Service_Contract;
8 use Booktics\Models\Appointment_Model;
9
10 class Order_Hooks implements Hookable_Service_Contract {
11
12 /**
13 * Register the hooks for the order model.
14 *
15 * @return void
16 */
17 public function register() {
18 add_action( 'booktics_order_filters', [
19 $this,
20 'team_member_order_filters'
21 ] );
22 }
23
24 /**
25 * Filter order conditions based on the current user's role.
26 *
27 * @param array $conditions The order conditions.
28 *
29 * @return array The filtered order conditions.
30 */
31 public function team_member_order_filters( $conditions ) {
32 $current_user = wp_get_current_user();
33 $roles = $current_user->roles;
34
35 if ( in_array( 'administrator', $roles, true ) ) {
36 return $conditions;
37 }
38
39 if ( in_array( 'booktics_team_member', $roles, true ) ) {
40 $order_ids = $this->get_order_ids();
41 $conditions['id'] = [ 'in', $order_ids ];
42 }
43
44 return $conditions;
45 }
46
47 /**
48 * Get order ids for a date range
49 *
50 * @param array $dates
51 *
52 * @return array
53 */
54 private function get_order_ids() {
55 $order_ids = ['null'];
56 $args = [];
57 $args = apply_filters( 'booktics_appointment_args', $args );
58 $appointments = ( new Appointment_Model() )->all( $args );
59 foreach ( $appointments as $appointment ) {
60 $order_ids[] = $appointment->order_id;
61 }
62
63 return $order_ids;
64 }
65 }