PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.3
Booking for Appointments and Events Calendar – Amelia v2.3
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 6 months ago
HelperService.php
85 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 * Helper method to add PHP vars to JS vars
23 *
24 * @param $varName
25 * @param $phpVar
26 */
27 public static function exportJSVar($varName, $phpVar)
28 {
29 self::$jsVars[$varName] = $phpVar;
30 }
31
32 /**
33 * Helper method to print PHP vars to JS vars
34 */
35 public static function printJSVars()
36 {
37 if (!empty(self::$jsVars)) {
38 $jsBlock = '<script type="text/javascript">';
39 foreach (self::$jsVars as $varName => $jsVar) {
40 $jsBlock .= "var {$varName} = " . json_encode($jsVar) . ';';
41 }
42 $jsBlock .= '</script>';
43 echo $jsBlock;
44 }
45 }
46
47 /**
48 * @param int $orderId
49 *
50 * @return string|null
51 */
52 public static function getWooCommerceOrderUrl($orderId)
53 {
54 return get_edit_post_link($orderId, '');
55 }
56
57 /**
58 * @param int $orderId
59 *
60 * @return array
61 */
62 public static function getWooCommerceOrderItemAmountValues($orderId)
63 {
64 $order = wc_get_order($orderId);
65
66 $prices = [];
67
68 if ($order) {
69 foreach ($order->get_items() as $itemId => $orderItem) {
70 $data = wc_get_order_item_meta($itemId, WooCommerceService::AMELIA);
71
72 if ($data && is_array($data)) {
73 $prices[$itemId] = [
74 'coupon' => (float)round($orderItem->get_subtotal() - $orderItem->get_total(), 2),
75 'tax' => !isset($data['taxIncluded']) || !$data['taxIncluded'] ?
76 (float)$orderItem->get_total_tax() : 0,
77 ];
78 }
79 }
80 }
81
82 return $prices;
83 }
84 }
85