PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.6
Booking for Appointments and Events Calendar – Amelia v2.4.6
2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Infrastructure / WP / HelperService / HelperService.php
ameliabooking / src / Infrastructure / WP / HelperService Last commit date
HelperService.php 4 weeks ago
HelperService.php
112 lines
1 <?php
2
3 /**
4 * @copyright © Melograno Ventures. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace AmeliaBooking\Infrastructure\WP\HelperService;
9
10 /**
11 * Class HelperService
12 *
13 * @package AmeliaBooking\Infrastructure\WP\HelperService
14 */
15 class HelperService
16 {
17 public static $jsVars = [];
18
19 /**
20 * Determine whether the site is using SSL.
21 *
22 * Supports setups behind reverse proxies where SSL is terminated
23 * before traffic reaches WordPress/PHP.
24 */
25 public static function isSSL(): bool
26 {
27 if (function_exists('is_ssl') && is_ssl()) {
28 return true;
29 }
30
31 if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
32 $forwardedProtos = explode(',', (string)$_SERVER['HTTP_X_FORWARDED_PROTO']);
33 if (in_array('https', $forwardedProtos)) {
34 return true;
35 }
36 }
37
38 if (
39 function_exists('get_option') &&
40 'https' === parse_url((string)get_option('siteurl'), PHP_URL_SCHEME)
41 ) {
42 return true;
43 }
44
45 return false;
46 }
47
48 /**
49 * Helper method to add PHP vars to JS vars
50 *
51 * @param $varName
52 * @param $phpVar
53 */
54 public static function exportJSVar($varName, $phpVar)
55 {
56 self::$jsVars[$varName] = $phpVar;
57 }
58
59 /**
60 * Helper method to print PHP vars to JS vars
61 */
62 public static function printJSVars()
63 {
64 if (!empty(self::$jsVars)) {
65 $jsBlock = '<script type="text/javascript">';
66 foreach (self::$jsVars as $varName => $jsVar) {
67 $jsBlock .= "var {$varName} = " . json_encode($jsVar) . ';';
68 }
69 $jsBlock .= '</script>';
70 echo $jsBlock;
71 }
72 }
73
74 /**
75 * @param int $orderId
76 *
77 * @return string|null
78 */
79 public static function getWooCommerceOrderUrl($orderId)
80 {
81 return get_edit_post_link($orderId, '');
82 }
83
84 /**
85 * @param int $orderId
86 *
87 * @return array
88 */
89 public static function getWooCommerceOrderItemAmountValues($orderId)
90 {
91 $order = wc_get_order($orderId);
92
93 $prices = [];
94
95 if ($order) {
96 foreach ($order->get_items() as $itemId => $orderItem) {
97 $data = wc_get_order_item_meta($itemId, 'ameliabooking');
98
99 if ($data && is_array($data)) {
100 $prices[$itemId] = [
101 'coupon' => (float)round($orderItem->get_subtotal() - $orderItem->get_total(), 2),
102 'tax' => !isset($data['taxIncluded']) || !$data['taxIncluded'] ?
103 (float)$orderItem->get_total_tax() : 0,
104 ];
105 }
106 }
107 }
108
109 return $prices;
110 }
111 }
112