PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
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 2 weeks ago
HelperService.php
114 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 use AmeliaBooking\Infrastructure\WP\Integrations\WooCommerce\WooCommerceService;
11
12 /**
13 * Class HelperService
14 *
15 * @package AmeliaBooking\Infrastructure\WP\HelperService
16 */
17 class HelperService
18 {
19 public static $jsVars = [];
20
21 /**
22 * Determine whether the site is using SSL.
23 *
24 * Supports setups behind reverse proxies where SSL is terminated
25 * before traffic reaches WordPress/PHP.
26 */
27 public static function isSSL(): bool
28 {
29 if (function_exists('is_ssl') && is_ssl()) {
30 return true;
31 }
32
33 if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
34 $forwardedProtos = explode(',', (string)$_SERVER['HTTP_X_FORWARDED_PROTO']);
35 if (in_array('https', $forwardedProtos)) {
36 return true;
37 }
38 }
39
40 if (
41 function_exists('get_option') &&
42 'https' === parse_url((string)get_option('siteurl'), PHP_URL_SCHEME)
43 ) {
44 return true;
45 }
46
47 return false;
48 }
49
50 /**
51 * Helper method to add PHP vars to JS vars
52 *
53 * @param $varName
54 * @param $phpVar
55 */
56 public static function exportJSVar($varName, $phpVar)
57 {
58 self::$jsVars[$varName] = $phpVar;
59 }
60
61 /**
62 * Helper method to print PHP vars to JS vars
63 */
64 public static function printJSVars()
65 {
66 if (!empty(self::$jsVars)) {
67 $jsBlock = '<script type="text/javascript">';
68 foreach (self::$jsVars as $varName => $jsVar) {
69 $jsBlock .= "var {$varName} = " . json_encode($jsVar) . ';';
70 }
71 $jsBlock .= '</script>';
72 echo $jsBlock;
73 }
74 }
75
76 /**
77 * @param int $orderId
78 *
79 * @return string|null
80 */
81 public static function getWooCommerceOrderUrl($orderId)
82 {
83 return get_edit_post_link($orderId, '');
84 }
85
86 /**
87 * @param int $orderId
88 *
89 * @return array
90 */
91 public static function getWooCommerceOrderItemAmountValues($orderId)
92 {
93 $order = wc_get_order($orderId);
94
95 $prices = [];
96
97 if ($order) {
98 foreach ($order->get_items() as $itemId => $orderItem) {
99 $data = wc_get_order_item_meta($itemId, WooCommerceService::AMELIA);
100
101 if ($data && is_array($data)) {
102 $prices[$itemId] = [
103 'coupon' => (float)round($orderItem->get_subtotal() - $orderItem->get_total(), 2),
104 'tax' => !isset($data['taxIncluded']) || !$data['taxIncluded'] ?
105 (float)$orderItem->get_total_tax() : 0,
106 ];
107 }
108 }
109 }
110
111 return $prices;
112 }
113 }
114