PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 4.6.9
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v4.6.9
4.9.1 4.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.1 3.0.0 3.1.0 3.1.1 4.0.0 4.0.1 4.1.0 4.1.1 4.2.0 4.2.1 4.3.0 4.3.1 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.6.8 4.6.9 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.8.9 trunk 0.1.2-beta 0.1.3-beta 0.1.4-beta 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.5.0 1.5.1 1.6.0 1.6.1 1.7.0 1.8.0 1.8.1 1.9.0
shopengine / core / builders / base.php
shopengine / core / builders Last commit date
action.php 1 year ago api.php 4 years ago base.php 2 years ago hooks.php 3 years ago templates.php 3 years ago
base.php
262 lines
1 <?php
2
3 namespace ShopEngine\Core\Builders;
4
5 use ShopEngine\Base\Common;
6 use ShopEngine\Core\Export_Import\Export;
7 use ShopEngine\Core\Export_Import\Import;
8 use ShopEngine\Core\PageTemplates\Page_Templates;
9 use ShopEngine\Core\Template_Cpt;
10 use ShopEngine\Traits\Singleton;
11 use ShopEngine\Utils\Elementor_Data_Map;
12
13 defined('ABSPATH') || exit;
14
15 class Base extends Common {
16
17 use Singleton;
18
19 // $api variable call for Cpt Class Instance
20 public $form;
21
22 // $api variable call for Api Class Instance
23 public $api;
24
25 public function get_dir() {
26
27 return dirname(__FILE__);
28 }
29
30
31 /**
32 *
33 * @since 1.0.0
34 *
35 */
36 public function init() {
37
38 $this->api = new Api();
39
40 #Registering custom post type
41 Template_Cpt::instance()->init();
42
43 $cpt_type = Template_Cpt::TYPE;
44
45 #All hooks
46 Hooks::instance()->init();
47
48 add_filter("theme_{$cpt_type}_templates", [$this, 'add_page_templates'], 999, 4);
49 add_filter("elementor/document/urls/wp_preview", [$this, 'change_preview_editor_url'], 999, 2);
50 add_filter( 'preview_post_link', [$this, 'modify_gutenberg_preview_url'], 999, 2);
51
52
53 add_action('wp', [Page_Templates::instance(), 'init'], 999);
54
55 add_filter('woocommerce_checkout_fields', [$this, 'disabling_fields'], 999);
56
57 (new Export())->init();
58 (new Import())->init();
59 }
60
61 public function modify_gutenberg_preview_url( $modified_url, $post ) {
62 $post_id = $post->ID;
63 $template = \ShopEngine\Core\Builders\Templates::get_registered_template_data($post_id);
64
65 if ( empty( $template ) || ! isset( $template['url'] ) || get_post_type( $post_id ) !== Template_Cpt::TYPE ) {
66 return $modified_url;
67 }
68
69 $param = [
70 'shopengine_template_id' => $post_id,
71 'preview_nonce' => wp_create_nonce( 'template_preview_' . $post_id ),
72 'change_template' => '1',
73 ];
74
75 $modified_url = \ShopEngine\Utils\Helper::add_to_url( $template['url'], $param );
76
77
78 return $modified_url;
79 }
80
81 public function change_preview_editor_url($url, $document) {
82 $post_id = $document->get_main_id();
83 $template = \ShopEngine\Core\Builders\Templates::get_registered_template_data($post_id);
84
85 if(empty($template) || !isset($template['url']) || get_post_type($post_id) !== Template_Cpt::TYPE) {
86 return $url;
87 }
88
89 $param = [
90 'shopengine_template_id' => $post_id,
91 'preview_nonce' => wp_create_nonce('template_preview_' . $post_id),
92 'change_template' => '1',
93 ];
94
95 $url = \ShopEngine\Utils\Helper::add_to_url($template['url'], $param);
96
97
98 return $url;
99 }
100
101
102
103 public function add_page_templates($page_templates, $wp_theme, $post) {
104
105 unset($page_templates['elementor_theme']);
106
107 $page_templates['shopengine_canvas_tpl'] = esc_html__('Shopengine Canvas', 'shopengine');
108 $page_templates['shopengine_full_width_tpl'] = esc_html__('Shopengine Full width', 'shopengine');
109
110 return $page_templates;
111 }
112
113 public function disabling_fields($fields) {
114
115 // checkout page
116 // - is any checkout template active ?
117 // - - then it is overriding the template
118 // - - - then add the filter
119
120 if(is_checkout()) {
121
122 $template_id = $this->get_template_id('checkout');
123
124 if(!empty($template_id)) {
125
126 $current_page_id = get_the_ID();
127 $mapper = new Elementor_Data_Map();
128
129 $dt = $mapper->get_elementor_data($template_id);
130 $els = $mapper->get_widget_data('shopengine-checkout-form-billing', $dt);
131
132 if(!empty($els[0]->settings)) {
133
134 $obj = $els[0]->settings;
135 unset($els);
136
137 if(!empty($obj->shopengine_hide_billing_first_name_field)) {
138
139 unset($fields['billing']['billing_first_name']);
140 }
141
142 if(!empty($obj->shopengine_hide_billing_last_name_field)) {
143
144 unset($fields['billing']['billing_last_name']);
145 }
146
147 if(!empty($obj->shopengine_hide_billing_company_field)) {
148
149 unset($fields['billing']['billing_company']);
150 }
151
152 if(!empty($obj->shopengine_hide_billing_country_field)) {
153
154 unset($fields['billing']['billing_country']);
155 }
156
157 if(!empty($obj->shopengine_hide_billing_address_1_field)) {
158
159 unset($fields['billing']['billing_address_1']);
160 }
161
162 if(!empty($obj->shopengine_hide_billing_address_2_field)) {
163
164 unset($fields['billing']['billing_address_2']);
165 }
166
167 if(!empty($obj->shopengine_hide_billing_city_field)) {
168
169 unset($fields['billing']['billing_city']);
170 }
171
172 if(!empty($obj->shopengine_hide_billing_state_field)) {
173
174 unset($fields['billing']['billing_state']);
175 }
176
177 if(!empty($obj->shopengine_hide_billing_postcode_field)) {
178
179 unset($fields['billing']['billing_postcode']);
180 }
181
182 if(!empty($obj->shopengine_hide_billing_phone_field)) {
183
184 unset($fields['billing']['billing_phone']);
185 }
186
187 if(!empty($obj->shopengine_hide_billing_email_field)) {
188
189 unset($fields['billing']['billing_email']);
190 }
191 }
192
193 $els = $mapper->get_widget_data('shopengine-checkout-form-shipping', $dt);
194
195 if(!empty($els[0]->settings)) {
196
197 $obj = $els[0]->settings;
198 unset($els);
199
200 if(!empty($obj->shopengine_hide_billing_first_name_field)) {
201
202 unset($fields['shipping']['shipping_first_name']);
203 }
204
205 if(!empty($obj->shopengine_hide_shipping_last_name_field)) {
206
207 unset($fields['shipping']['shipping_last_name']);
208 }
209
210 if(!empty($obj->shopengine_hide_shipping_company_field)) {
211
212 unset($fields['shipping']['shipping_company']);
213 }
214
215 if(!empty($obj->shopengine_hide_shipping_country_field)) {
216
217 unset($fields['shipping']['shipping_country']);
218 }
219
220 if(!empty($obj->shopengine_hide_shipping_address_1_field)) {
221
222 unset($fields['shipping']['shipping_address_1']);
223 }
224
225 if(!empty($obj->shopengine_hide_shipping_address_2_field)) {
226
227 unset($fields['shipping']['shipping_address_2']);
228 }
229
230 if(!empty($obj->shopengine_hide_shipping_city_field)) {
231
232 unset($fields['shipping']['shipping_city']);
233 }
234
235 if(!empty($obj->shopengine_hide_shipping_state_field)) {
236
237 unset($fields['shipping']['shipping_state']);
238 }
239
240 if(!empty($obj->shopengine_hide_shipping_postcode_field)) {
241
242 unset($fields['shipping']['shipping_postcode']);
243 }
244 }
245
246 } else {
247
248 // var_dump('ohh....... no checkout template is active!');
249
250 }
251 }
252
253
254 return $fields;
255 }
256
257 public function get_template_id($type) {
258
259 return \ShopEngine\Core\Builders\Templates::get_registered_template_id($type);
260 }
261 }
262