PluginProbe
Orderable – Restaurant & Food Ordering System / 1.10.0
Orderable – Restaurant & Food Ordering System v1.10.0
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.10.0, at inc/modules/services/class-services.php

120 lines 2.4 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 ( ! is_string( $shipping_method ) ) {
55 $shipping_method = $shipping_method->get_method_id();
56 }
57
58 $explode = explode( ':', $shipping_method );
59
60 return false !== strpos( $explode[0], 'pickup' );
61 }
62
63 /**
64 * Get selected service.
65 *
66 * @param bool $label Return the label?
67 *
68 * @return bool|WC_Shipping_Method
69 */
70 public static function get_selected_service( $label = true ) {
71 if ( empty( WC()->session ) ) {
72 return false;
73 }
74
75 $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
76
77 if ( empty( $chosen_methods ) ) {
78 return false;
79 }
80
81 $chosen_method = $chosen_methods[0];
82 $is_pickup = self::is_pickup_method( $chosen_method );
83 $type = $is_pickup ? 'pickup' : 'delivery';
84
85 if ( ! $label ) {
86 return $type;
87 }
88
89 return self::get_service_label( $type );
90 }
91
92 /**
93 * Get service label.
94 *
95 * @param string $type pickup|delivery
96 * @param bool $plural Return the plural label?
97 *
98 * @return bool|string
99 */
100 public static function get_service_label( $type, $plural = false ) {
101 if ( empty( $type ) ) {
102 return false;
103 }
104
105 $type = $plural ? $type . '_plural' : $type;
106
107 $labels = apply_filters( 'orderable_service_labels', array(
108 'pickup' => __( 'Pickup', 'orderable' ),
109 'delivery' => __( 'Delivery', 'orderable' ),
110 'pickup_plural' => __( 'Pickups', 'orderable' ),
111 'delivery_plural' => __( 'Deliveries', 'orderable' ),
112 ) );
113
114 if ( ! isset( $labels[ $type ] ) ) {
115 return false;
116 }
117
118 return $labels[ $type ];
119 }
120 }