PluginProbe
Orderable – Restaurant & Food Ordering System / 1.20.1
Orderable – Restaurant & Food Ordering System v1.20.1
0.1.4 0.1.5 0.2.0 1.0.0 1.1.0 1.1.1 1.10.0 1.10.1 1.11.0 1.12.0 1.12.1 1.12.2 1.13.0 1.14.0 1.15.0 1.16.0 1.17.0 1.17.1 1.18.0 1.19.0 1.19.1 1.19.2 1.2.0 1.20.0 1.20.1 All 44 releases
orderable / inc / modules / services / class-services.php

class-services.php in Orderable – Restaurant & Food Ordering System 1.20.1, at inc/modules/services/class-services.php

128 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Module: Services.
4 *
5 * Delivery/pickup services.
6 *
7 * @package Orderable/Classes
8 */
9
10 defined( 'ABSPATH' ) || exit;
11
12 /**
13 * Services module class.
14 */
15 class Orderable_Services {
16 /**
17 * Init.
18 */
19 public static function run() {
20 self::load_classes();
21 }
22
23 /**
24 * Load classes for this module.
25 */
26 public static function load_classes() {
27 $classes = array(
28 'services-order' => 'Orderable_Services_Order',
29 );
30
31 foreach ( $classes as $file_name => $class_name ) {
32 require_once ORDERABLE_MODULES_PATH . 'services/class-' . $file_name . '.php';
33
34 $class_name::run();
35 }
36 }
37
38 /**
39 * Is pickup method?
40 *
41 * @param string|WC_Shipping_Method $shipping_method
42 *
43 * @return bool
44 */
45 public static function is_pickup_method( $shipping_method ) {
46 if ( ! $shipping_method ) {
47 return false;
48 }
49
50 if ( is_numeric( $shipping_method ) ) {
51 $shipping_method = Orderable_Location_Zones::get_method_id( $shipping_method );
52 }
53
54 if ( ! $shipping_method ) {
55 return false;
56 }
57
58 if ( ! is_string( $shipping_method ) ) {
59 $shipping_method = $shipping_method->get_method_id();
60 }
61
62 $explode = explode( ':', $shipping_method );
63
64 return false !== strpos( $explode[0], 'pickup' );
65 }
66
67 /**
68 * Get selected service.
69 *
70 * @param bool $label Return the label?
71 *
72 * @return bool|WC_Shipping_Method
73 */
74 public static function get_selected_service( $label = true ) {
75 if ( empty( WC()->session ) ) {
76 return false;
77 }
78
79 $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
80
81 if ( empty( $chosen_methods[0] ) ) {
82 return false;
83 }
84
85 $chosen_method = $chosen_methods[0];
86 $is_pickup = self::is_pickup_method( $chosen_method );
87 $type = $is_pickup ? 'pickup' : 'delivery';
88
89 if ( ! $label ) {
90 return $type;
91 }
92
93 return self::get_service_label( $type );
94 }
95
96 /**
97 * Get service label.
98 *
99 * @param string $type pickup|delivery
100 * @param bool $plural Return the plural label?
101 *
102 * @return bool|string
103 */
104 public static function get_service_label( $type, $plural = false ) {
105 if ( empty( $type ) ) {
106 return false;
107 }
108
109 $type = $plural ? $type . '_plural' : $type;
110
111 $labels = apply_filters(
112 'orderable_service_labels',
113 array(
114 'pickup' => __( 'Pickup', 'orderable' ),
115 'delivery' => __( 'Delivery', 'orderable' ),
116 'pickup_plural' => __( 'Pickups', 'orderable' ),
117 'delivery_plural' => __( 'Deliveries', 'orderable' ),
118 )
119 );
120
121 if ( ! isset( $labels[ $type ] ) ) {
122 return false;
123 }
124
125 return $labels[ $type ];
126 }
127 }
128