-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEES_Espresso_Promotions.shortcode.php
111 lines (102 loc) · 3.57 KB
/
EES_Espresso_Promotions.shortcode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* Class EES_Espresso_Promotions
* Description
*
* @package Event Espresso
* @subpackage espresso-promotions
* @author Brent Christensen
* @since 1.0.0
*/
class EES_Espresso_Promotions extends EES_Shortcode
{
/**
* set_hooks - for hooking into EE Core, modules, etc
*
* @return void
*/
public static function set_hooks()
{
}
/**
* set_hooks_admin - for hooking into EE Admin Core, modules, etc
*
* @return void
*/
public static function set_hooks_admin()
{
}
/**
* set_definitions
*
* @return void
*/
public static function set_definitions()
{
}
/**
* run - initial shortcode module setup called during "wp_loaded" hook
* this method is primarily used for loading resources that will be required by the shortcode when it is actually
* processed
*
* @param WP $WP
* @return void
*/
public function run(WP $WP)
{
EED_Promotions::$shortcode_active = true;
EED_Promotions::enqueue_scripts();
}
/**
* [ESPRESSO_PROMOTIONS]
*
* @param array|string $attributes
* @return string
* @throws EE_Error
* @throws ReflectionException
*/
public function process_shortcode($attributes = []): string
{
/** @type EEM_Promotion $EEM_Promotion */
$EEM_Promotion = EE_Registry::instance()->load_model('Promotion');
EE_Registry::instance()->load_helper('Template');
$active_promotions = $EEM_Promotion->get_all_active_codeless_promotions();
$html = '<div id="ee-upcoming-promotions-dv">';
foreach ($active_promotions as $promotion) {
if ($promotion instanceof EE_Promotion) {
$config = EED_Promotions::instance()->set_config();
if (
! empty($config->banner_template)
&& $config->banner_template == 'promo-banner-ribbon.template.php'
&& ! empty($config->ribbon_banner_color)
) {
$promo_bg_color = $config->ribbon_banner_color;
} else {
$promo_bg_color = '';
}
$scope_objects = $promotion->get_objects_promo_applies_to();
$html .= EEH_Template::locate_template(
apply_filters(
'FHEE__EED_Promotions__process_shortcode__upcoming_promotions',
EE_PROMOTIONS_PATH . 'templates' . DS . 'upcoming-promotions-grid.template.php'
),
[
'PRO_ID' => $promotion->ID(),
'promo_bg_color' => apply_filters(
'FHEE__EED_Promotions__process_shortcode__promo_bg_color',
$promo_bg_color
),
'promo_header' => $promotion->name(),
'promo_desc' => $promotion->description() != '' ? $promotion->description() . '<br />' : '',
'promo_amount' => $promotion->pretty_amount(),
'promo_dates' => $promotion->promotion_date_range(),
'promo_scopes' => $promotion->get_promo_applies_to_link_array($scope_objects),
'promo_is_global' => $promotion->is_global(),
]
);
}
}
$html .= '</div>';
return $html;
}
}