PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
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 years ago
HelperService.php
84 lines
1 <?php
2 /**
3 * @copyright © TMS-Plugins. All rights reserved.
4 * @licence See LICENCE.md for license details.
5 */
6
7 namespace AmeliaBooking\Infrastructure\WP\HelperService;
8
9 use AmeliaBooking\Infrastructure\WP\Integrations\WooCommerce\WooCommerceService;
10
11 /**
12 * Class HelperService
13 *
14 * @package AmeliaBooking\Infrastructure\WP\HelperService
15 */
16 class HelperService
17 {
18 public static $jsVars = [];
19
20 /**
21 * Helper method to add PHP vars to JS vars
22 *
23 * @param $varName
24 * @param $phpVar
25 */
26 public static function exportJSVar($varName, $phpVar)
27 {
28 self::$jsVars[$varName] = $phpVar;
29 }
30
31 /**
32 * Helper method to print PHP vars to JS vars
33 */
34 public static function printJSVars()
35 {
36 if (!empty(self::$jsVars)) {
37 $jsBlock = '<script type="text/javascript">';
38 foreach (self::$jsVars as $varName => $jsVar) {
39 $jsBlock .= "var {$varName} = " . json_encode($jsVar) . ';';
40 }
41 $jsBlock .= '</script>';
42 echo $jsBlock;
43 }
44 }
45
46 /**
47 * @param int $orderId
48 *
49 * @return string|null
50 */
51 public static function getWooCommerceOrderUrl($orderId)
52 {
53 return get_edit_post_link($orderId, '');
54 }
55
56 /**
57 * @param int $orderId
58 *
59 * @return array
60 */
61 public static function getWooCommerceOrderItemAmountValues($orderId)
62 {
63 $order = wc_get_order($orderId);
64
65 $prices = [];
66
67 if ($order) {
68 foreach ($order->get_items() as $itemId => $orderItem) {
69 $data = wc_get_order_item_meta($itemId, WooCommerceService::AMELIA);
70
71 if ($data && is_array($data)) {
72 $prices[$itemId] = [
73 'coupon' => (float)round($orderItem->get_subtotal() - $orderItem->get_total(), 2),
74 'tax' => !isset($data['taxIncluded']) || !$data['taxIncluded'] ?
75 (float)$orderItem->get_total_tax() : 0,
76 ];
77 }
78 }
79 }
80
81 return $prices;
82 }
83 }
84