PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.56
E2Pdf – Export Pdf Tool for WordPress v1.32.56
1.32.55 1.32.56 1.32.53 1.32.51 1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 All 76 releases
e2pdf / classes / extension / e2pdf-woocommerce.php

e2pdf-woocommerce.php in E2Pdf – Export Pdf Tool for WordPress 1.32.56, at classes/extension/e2pdf-woocommerce.php

4,107 lines 260.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * E2Pdf WooCommerce Extension
5 * @copyright Copyright 2017 https://e2pdf.com
6 * @license GPLv3
7 * @version 1
8 * @link https://e2pdf.com
9 * @since 1.09.07
10 */
11 if (!defined('ABSPATH')) {
12 die('Access denied.');
13 }
14
15 class Extension_E2pdf_Woocommerce extends Model_E2pdf_Model {
16
17 private $options;
18 private $info = array(
19 'key' => 'woocommerce',
20 'title' => 'WooCommerce',
21 );
22
23 /**
24 * Get info about extension
25 * @param string $key - Key to get assigned extension info value
26 * @return array|string - Extension Key and Title or Assigned extension info value
27 */
28 public function info($key = false) {
29 if ($key && isset($this->info[$key])) {
30 return $this->info[$key];
31 } else {
32 return array(
33 $this->info['key'] => $this->info['title'],
34 );
35 }
36 }
37
38 /**
39 * Check if needed plugin active
40 * @return bool - Activated/Not Activated plugin
41 */
42 public function active() {
43 if (defined('E2PDF_WOOCOMMERCE_EXTENSION') || $this->helper->load('extension')->is_plugin_active('woocommerce/woocommerce.php')) {
44 return true;
45 }
46 return false;
47 }
48
49 /**
50 * Set option
51 * @param string $key - Key of option
52 * @param string $value - Value of option
53 * @return bool - Status of setting option
54 */
55 public function set($key, $value) {
56 if (!isset($this->options)) {
57 $this->options = new stdClass();
58 }
59 $this->options->$key = $value;
60 switch ($key) {
61 case 'dataset':
62 $this->set('cached_post', false);
63 if ($this->get('dataset')) {
64 $this->set('cached_post', get_post($this->get('dataset')));
65 }
66 break;
67 default:
68 break;
69 }
70 }
71
72 /**
73 * Get option by key
74 * @param string $key - Key to get assigned option value
75 * @return mixed
76 */
77 public function get($key) {
78 if (isset($this->options->$key)) {
79 $value = $this->options->$key;
80 } else {
81 switch ($key) {
82 case 'args':
83 $value = array();
84 break;
85 default:
86 $value = false;
87 break;
88 }
89 }
90 return $value;
91 }
92
93 /**
94 * Get items to work with
95 * @return array() - List of available items
96 */
97 public function items() {
98 $items = array();
99 $forms = array(
100 'product',
101 'product_variation',
102 'shop_order',
103 'shop_subscription',
104 'cart',
105 );
106 foreach ($forms as $form) {
107 $item = $this->item($form);
108 if (!empty($item->id)) {
109 $items[] = $this->item($form);
110 }
111 }
112 return $items;
113 }
114
115 /**
116 * Get entries for export
117 * @param string $item_id - Item ID
118 * @param string $name - Entries names
119 * @return array() - Entries list
120 */
121 public function datasets($item_id = false, $name = false) {
122 $datasets = array();
123 $entries = array();
124 if ($item_id) {
125 if ($item_id == 'cart') {
126 if (function_exists('wc_get_page_id') && wc_get_page_id('cart')) {
127 $entries = get_posts(
128 array(
129 'post_type' => 'any',
130 'post__in' => array(wc_get_page_id('cart')),
131 'numberposts' => -1,
132 'post_status' => 'any',
133 )
134 );
135 }
136 } elseif ($item_id == 'shop_order' && get_option('woocommerce_custom_orders_table_enabled') === 'yes' && get_option('woocommerce_custom_orders_table_data_sync_enabled') !== 'yes') {
137 $entries = get_posts(
138 array(
139 'post_type' => 'shop_order_placehold',
140 'numberposts' => -1,
141 'post_status' => 'any',
142 )
143 );
144 } else {
145 $entries = get_posts(
146 array(
147 'post_type' => $item_id,
148 'numberposts' => -1,
149 'post_status' => 'any',
150 )
151 );
152 }
153 if ($entries) {
154 $this->set('item', $item_id);
155 foreach ($entries as $key => $entry) {
156 $this->set('dataset', $entry->ID);
157 $entry_title = $this->render($name);
158 if (!$entry_title) {
159 $entry_title = isset($entry->post_title) && $entry->post_title ? $entry->post_title : $entry->ID;
160 }
161 $datasets[] = array(
162 'key' => $entry->ID,
163 'value' => $entry_title,
164 );
165 }
166 }
167 }
168 return $datasets;
169 }
170
171 /**
172 * Get item
173 * @param string $item_id - Item ID
174 * @return object - Item
175 */
176 public function item($item_id = false) {
177 if (!$item_id && $this->get('item')) {
178 $item_id = $this->get('item');
179 }
180 $item = new stdClass();
181 $form = get_post_type_object($item_id);
182 if ($form) {
183 $item->id = $item_id;
184 $item->name = $form->label ? $form->label : $item_id;
185 $item->url = $this->helper->get_url(array('post_type' => $item_id), 'edit.php?');
186 } elseif ($item_id == 'cart' && function_exists('wc_get_page_id')) {
187 $item->id = $item_id;
188 $item->name = __('Cart / Checkout', 'e2pdf');
189 $item->url = $this->helper->get_url(
190 array(
191 'post' => wc_get_page_id('cart'),
192 'action' => 'edit',
193 ), 'post.php?'
194 );
195 } else {
196 $item->id = '';
197 $item->name = '';
198 $item->url = '';
199 }
200 return $item;
201 }
202
203 /**
204 * Get Dataset Actions
205 * @param int $dataset_id - Dataset ID
206 * @return object
207 */
208 public function get_dataset_actions($dataset_id = false) {
209 $dataset_id = (int) $dataset_id;
210 if (!$dataset_id) {
211 return false;
212 }
213 $actions = new stdClass();
214 $actions->view = $this->helper->get_url(
215 array(
216 'post' => $dataset_id,
217 'action' => 'edit',
218 ), 'post.php?'
219 );
220 $actions->delete = false;
221 return $actions;
222 }
223
224 /**
225 * Get Template Actions
226 * @param int $template - Template ID
227 * @return object
228 */
229 public function get_template_actions($template = false) {
230 $template = (int) $template;
231 if (!$template) {
232 return;
233 }
234 $actions = new stdClass();
235 $actions->delete = false;
236 return $actions;
237 }
238
239 public function load_actions() {
240 $email_actions = apply_filters(
241 'woocommerce_email_actions',
242 array(
243 'woocommerce_low_stock',
244 'woocommerce_no_stock',
245 'woocommerce_product_on_backorder',
246 'woocommerce_order_status_pending_to_processing',
247 'woocommerce_order_status_pending_to_completed',
248 'woocommerce_order_status_processing_to_cancelled',
249 'woocommerce_order_status_pending_to_failed',
250 'woocommerce_order_status_pending_to_on-hold',
251 'woocommerce_order_status_failed_to_processing',
252 'woocommerce_order_status_failed_to_completed',
253 'woocommerce_order_status_failed_to_on-hold',
254 'woocommerce_order_status_cancelled_to_processing',
255 'woocommerce_order_status_cancelled_to_completed',
256 'woocommerce_order_status_cancelled_to_on-hold',
257 'woocommerce_order_status_on-hold_to_processing',
258 'woocommerce_order_status_on-hold_to_cancelled',
259 'woocommerce_order_status_on-hold_to_failed',
260 'woocommerce_order_status_completed',
261 'woocommerce_order_fully_refunded',
262 'woocommerce_order_partially_refunded',
263 'woocommerce_new_customer_note',
264 'woocommerce_created_customer',
265 'ywgc_email_send_gift_card',
266 )
267 );
268
269 foreach ($email_actions as $email_action) {
270 add_action($email_action . '_notification', array($this, 'action_after_email'), 99);
271 }
272 add_action('woocommerce_after_resend_order_email', array($this, 'action_after_email'), 99);
273
274 /* Compatibility fix with Enforcing Rules enabled */
275 add_action('woocommerce_settings_products', array($this, 'action_enforcing_rules_enabled_check'), -10);
276 add_action('woocommerce_admin_process_product_object', array($this, 'action_enforcing_rules_enabled_check'));
277
278 /* https://wordpress.org/plugins/elementor/ */
279 add_action('elementor/widget/before_render_content', array($this, 'action_elementor_widget_before_render_content'));
280 add_action('elementor/frontend/widget/before_render', array($this, 'action_elementor_widget_before_render_content'), 5);
281
282 /* https://wordpress.org/plugins/happy-elementor-addons/ compatibility fix */
283 add_action('elementor/frontend/before_render', array($this, 'action_elementor_widget_before_render_content'), 0);
284
285 /* Temporary solution for File Downloads in WC Admin Order page */
286 add_action('add_meta_boxes_woocommerce_page_wc-orders', array($this, 'action_add_meta_boxes_woocommerce_page_wc_orders'));
287 add_action('add_meta_boxes_shop_order', array($this, 'action_add_meta_boxes_woocommerce_page_wc_orders'));
288 add_action('add_meta_boxes_shop_subscription', array($this, 'action_add_meta_boxes_woocommerce_page_wc_orders'));
289
290 /* Order Hooks */
291 add_action('add_meta_boxes', array($this, 'hook_woocommerce_order_edit'));
292 add_action('woocommerce_admin_order_actions_end', array($this, 'hook_woocommerce_order_row_actions'));
293 add_action('woocommerce_order_details_before_order_table', array($this, 'hook_woocommerce_order_details'));
294 add_action('woocommerce_order_details_before_order_table_items', array($this, 'hook_woocommerce_order_details'));
295 add_action('woocommerce_order_details_after_order_table_items', array($this, 'hook_woocommerce_order_details'));
296 add_action('woocommerce_order_details_after_order_table', array($this, 'hook_woocommerce_order_details'));
297 add_action('woocommerce_after_order_details', array($this, 'hook_woocommerce_order_details'));
298 add_action('woocommerce_proceed_to_checkout', array($this, 'hook_woocommerce_proceed_to_checkout'));
299 add_action('woocommerce_review_order_before_submit', array($this, 'hook_woocommerce_review_order'));
300 add_action('woocommerce_review_order_after_submit', array($this, 'hook_woocommerce_review_order'));
301
302 /* Subscription Hooks */
303 add_action('add_meta_boxes', array($this, 'hook_woocommerce_subscription_edit'));
304 add_action('woocommerce_subscription_before_actions', array($this, 'hook_woocommerce_subscription_details'));
305 add_action('woocommerce_subscription_after_actions', array($this, 'hook_woocommerce_subscription_details'));
306 add_action('wcs_subscription_details_table_before_dates', array($this, 'hook_woocommerce_subscription_details'));
307 add_action('wcs_subscription_details_table_before_payment_method', array($this, 'hook_woocommerce_subscription_details'));
308 add_action('wcs_subscription_details_table_after_dates', array($this, 'hook_woocommerce_subscription_details'));
309
310 //phpcs:disable
311 if (get_option('e2pdf_wc_cart_template_id', '0')) {
312 add_action('woocommerce_proceed_to_checkout', array($this, 'action_e2pdf_wc_cart_template_id'), (int) get_option('e2pdf_wc_cart_template_id_priority', '10'));
313 }
314 if (get_option('e2pdf_wc_checkout_template_id', '0') && get_option('e2pdf_wc_checkout_template_id_hook', 'woocommerce_review_order_before_submit') && in_array(get_option('e2pdf_wc_checkout_template_id_hook', 'woocommerce_review_order_before_submit'), array('woocommerce_review_order_before_submit', 'woocommerce_review_order_after_submit'))) {
315 add_action(get_option('e2pdf_wc_checkout_template_id_hook', 'woocommerce_review_order_before_submit'), array($this, 'action_e2pdf_wc_checkout_template_id'), (int) get_option('e2pdf_wc_checkout_template_id_priority', '10'));
316 }
317 if (get_option('e2pdf_wc_order_details_template_id', '0') && get_option('e2pdf_wc_order_details_template_id_hook', 'woocommerce_order_details_before_order_table') && in_array(get_option('e2pdf_wc_order_details_template_id_hook', 'woocommerce_order_details_before_order_table'), array('woocommerce_order_details_before_order_table', 'woocommerce_order_details_before_order_table_items', 'woocommerce_order_details_after_order_table_items', 'woocommerce_order_details_after_order_table', 'woocommerce_after_order_details'))) {
318 add_action(get_option('e2pdf_wc_order_details_template_id_hook', 'woocommerce_order_details_before_order_table'), array($this, 'action_e2pdf_wc_order_details_template_id'), (int) get_option('e2pdf_wc_order_details_template_id_priority', '10'));
319 }
320 if (get_option('e2pdf_wc_admin_order_actions_template_id', '0') && get_option('e2pdf_wc_admin_order_actions_template_id_hook', 'woocommerce_admin_order_actions_end') && in_array(get_option('e2pdf_wc_admin_order_actions_template_id_hook', 'woocommerce_admin_order_actions_end'), array('woocommerce_admin_order_actions_start', 'woocommerce_admin_order_actions_end'))) {
321 add_action(get_option('e2pdf_wc_admin_order_actions_template_id_hook', 'woocommerce_admin_order_actions_end'), array($this, 'action_e2pdf_wc_admin_order_actions_template_id'), (int) get_option('e2pdf_wc_admin_order_actions_template_id_priority', '10'));
322 }
323 if (get_option('e2pdf_wc_admin_order_details_template_id', '0')) {
324 add_action('add_meta_boxes', array($this, 'action_add_meta_boxes'));
325 }
326 //phpcs:enable
327 }
328
329 public function load_filters() {
330 add_filter('woocommerce_product_file_download_path', array($this, 'filter_woocommerce_product_file_download_path'), 10, 3);
331 add_filter('woocommerce_short_description', array($this, 'filter_content_custom'));
332 add_filter('the_content', array($this, 'filter_the_content'), 10, 2);
333 add_filter('woocommerce_email_attachments', array($this, 'filter_woocommerce_email_attachments'), 10, 4);
334 add_filter('woocommerce_mail_content', array($this, 'filter_woocommerce_mail_content'), 99);
335 add_filter('woocommerce_display_product_attributes', array($this, 'filter_woocommerce_display_product_attributes'), 10, 2);
336 add_filter('e2pdf_model_shortcode_wc_product_get_attribute_value', array($this, 'filter_e2pdf_model_shortcode_wc_product_get_attribute_value'), 10, 2);
337 add_filter('woocommerce_customer_available_downloads', array($this, 'filter_download_urls'));
338 add_filter('woocommerce_order_get_downloadable_items', array($this, 'filter_download_urls'));
339
340 /* Flatsome theme global tab content */
341 add_filter('theme_mod_tab_content', array($this, 'filter_content_custom'));
342
343 /* Variable Product Short Description Dynamic ID */
344 add_filter('woocommerce_available_variation', array($this, 'filter_woocommerce_available_variation'), 10, 3);
345
346 /* PDF download link with E2Pdf shortcodes */
347 add_filter('e2pdf_model_shortcode_e2pdf_wc_product_description', array($this, 'filter_the_content'), 10, 2);
348
349 /* Compatibility fix with Enforcing Rules enabled */
350 add_filter('woocommerce_product_downloads_approved_directory_validation_for_shortcodes', array($this, 'filter_woocommerce_product_downloads_approved_directory_validation_for_shortcodes'), 99);
351
352 /**
353 * Cornerstone Builder
354 * https://theme.co/cornerstone/
355 */
356 add_filter('cs_element_pre_render', array($this, 'filter_cs_element_pre_render'));
357
358 /* Order Hooks */
359 add_filter('manage_edit-shop_order_columns', array($this, 'hook_woocommerce_order_row_column'));
360 add_filter('woocommerce_my_account_my_orders_actions', array($this, 'hook_woocommerce_my_account_my_orders_actions'), 10, 2);
361
362 /* Subscription Hooks */
363 add_filter('manage_edit-shop_subscription_columns', array($this, 'hook_woocommerce_subscription_row_column'), 11);
364 add_filter('wcs_view_subscription_actions', array($this, 'hook_wcs_view_subscription_actions'), 11, 2);
365
366 //phpcs:disable
367 if (get_option('e2pdf_wc_my_orders_actions_template_id', '0')) {
368 add_filter('woocommerce_my_account_my_orders_actions', array($this, 'filter_woocommerce_my_account_my_orders_actions'), (int) get_option('e2pdf_wc_checkout_template_id_priority', '10'), 2);
369 }
370 add_filter('e2pdf_model_options_get_options_options', array($this, 'filter_e2pdf_model_options_get_options_options'));
371 //phpcs:enable
372 // extension hooks
373 add_filter('e2pdf_extension_hooks', function ($hooks) {
374 $hooks[$this->info['key'] . '_shop_order'] = [
375 'hook_woocommerce_order_edit' => __('WP Admin Order Details', 'e2pdf'),
376 'hook_woocommerce_order_row_actions' => __('WP Admin Order List Actions', 'e2pdf'),
377 'hook_woocommerce_order_row_column' => __('WP Admin Order List Column', 'e2pdf'),
378 'hook_woocommerce_my_account_my_orders_actions' => __('User Order List', 'e2pdf'),
379 'hook_woocommerce_order_details_before_order_table' => __('User Order Details (Before Order Table)', 'e2pdf'),
380 'hook_woocommerce_order_details_before_order_table_items' => __('User Order Details (Before Order Table Items)', 'e2pdf'),
381 'hook_woocommerce_order_details_after_order_table_items' => __('User Order Details (After Order Table Items)', 'e2pdf'),
382 'hook_woocommerce_order_details_after_order_table' => __('User Order Details (After Order Table)', 'e2pdf'),
383 'hook_woocommerce_after_order_details' => __('User Order Details (After Order Details)', 'e2pdf')
384 ];
385 $hooks[$this->info['key'] . '_shop_subscription'] = [
386 'hook_woocommerce_subscription_edit' => __('WP Admin Subscription Details', 'e2pdf'),
387 'hook_woocommerce_subscription_row_column' => __('WP Admin Order List Column', 'e2pdf'),
388 'hook_woocommerce_subscription_before_actions' => __('User Subscription (Before Actions)', 'e2pdf'),
389 'hook_woocommerce_subscription_after_actions' => __('User Subscription (After Actions)', 'e2pdf'),
390 'hook_wcs_subscription_details_table_before_dates' => __('User Subscription (Before Dates)', 'e2pdf'),
391 'hook_wcs_subscription_details_table_after_dates' => __('User Subscription (After Dates)', 'e2pdf'),
392 'hook_wcs_subscription_details_table_before_payment_method' => __('User Subscription (Before Payment Method)', 'e2pdf'),
393 'hook_wcs_view_subscription_actions' => __('User Subscrition (Actions)', 'e2pdf')
394 ];
395 $hooks[$this->info['key'] . '_cart'] = [
396 'hook_woocommerce_proceed_to_checkout' => __('User Cart', 'e2pdf'),
397 'hook_woocommerce_review_order_before_submit' => __('User Checkout (Before Submit)', 'e2pdf'),
398 'hook_woocommerce_review_order_after_submit' => __('User Checkout (After Submit)', 'e2pdf')
399 ];
400 return $hooks;
401 });
402 }
403
404 // action after email
405 public function action_after_email() {
406 $files = $this->helper->get('woocommerce_attachments');
407 if (is_array($files) && !empty($files)) {
408 foreach ($files as $key => $file) {
409 $this->helper->delete_dir(dirname($file) . '/');
410 }
411 $this->helper->deset('woocommerce_attachments');
412 }
413 }
414
415 public function action_enforcing_rules_enabled_check() {
416 if (get_option('wc_downloads_approved_directories_mode') === 'enabled') {
417 if (class_exists('Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories\Register')) {
418 try {
419 $download_directories = wc_get_container()->get(Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories\Register::class);
420 $directory_id = $download_directories->add_approved_directory('file://./');
421 if ($directory_id) {
422 $download_directories->enable_by_id($directory_id);
423 }
424 } catch (Exception $e) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
425 }
426 }
427 }
428 }
429
430 public function filter_cs_element_pre_render($data) {
431 if (!empty($data['_type']) && $data['_type'] == 'raw-content' && !empty($data['raw_content']) && !empty($data['_p'])) {
432 $data['raw_content'] = $this->filter_content($data['raw_content'], $data['_p']);
433 }
434 return $data;
435 }
436
437 public function action_elementor_widget_before_render_content($widget) {
438 if ($widget && ($widget->get_name() == 'shortcode' || $widget->get_name() == 'text-editor')) {
439 $content = $widget->get_name() == 'shortcode' ? $widget->get_settings('shortcode') : $widget->get_settings('editor');
440 if ($content && false !== strpos($content, '[e2pdf-')) {
441 $wp_reset_postdata = true;
442 if (class_exists('\ElementorPro\Plugin') && class_exists('\ElementorPro\Modules\LoopBuilder\Documents\Loop')) {
443 $document = \ElementorPro\Plugin::elementor()->documents->get_current();
444 if ($document && $document instanceof \ElementorPro\Modules\LoopBuilder\Documents\Loop) {
445 $wp_reset_postdata = false;
446 }
447 }
448 if ($widget->get_name() == 'shortcode') {
449 $widget->set_settings('shortcode', $this->filter_content($content, false, false, $wp_reset_postdata));
450 } elseif ($widget->get_name() == 'text-editor' && !$wp_reset_postdata) {
451 $widget->set_settings('editor', $this->filter_content($content, false, false, $wp_reset_postdata));
452 }
453 }
454 }
455 }
456
457 public function action_add_meta_boxes_woocommerce_page_wc_orders($post) {
458 if (class_exists('Automattic\WooCommerce\Utilities\OrderUtil') && method_exists('Automattic\WooCommerce\Utilities\OrderUtil', 'is_order_edit_screen') && class_exists('WC_Data_Store')) {
459 if (Automattic\WooCommerce\Utilities\OrderUtil::is_order_edit_screen() || Automattic\WooCommerce\Utilities\OrderUtil::is_order_edit_screen('shop_subscription')) {
460 if ($post instanceof WC_Order) {
461 $order_id = $post->get_id();
462 } else {
463 $order_id = $post->ID;
464 }
465 $data_store = WC_Data_Store::load('customer-download');
466 $download_permissions = array();
467 if (0 !== $order_id) {
468 $download_permissions = $data_store->get_downloads(
469 array(
470 'order_id' => $order_id,
471 'orderby' => 'product_id',
472 )
473 );
474 }
475 $product = null;
476 $items = array();
477 $download_links = array();
478 if ($download_permissions && count($download_permissions) > 0) {
479 foreach ($download_permissions as $download) {
480 if (!$product || $product->get_id() !== $download->get_product_id()) {
481 $product = wc_get_product($download->get_product_id());
482 }
483 if (!$product || !$product->exists() || !$product->has_file($download->get_download_id())) {
484 continue;
485 }
486 $file = $product->get_file($download->get_download_id());
487 if ($file && $file->get_file() && strpos($file->get_file(), '[e2pdf-download') !== false) {
488 global $wpdb;
489 if (isset($items[$download->get_download_id()])) {
490 $item_ids = $items[$download->get_download_id()];
491 } else {
492 $item_ids = array();
493 }
494 $item_id = $wpdb->get_var($wpdb->prepare('SELECT `items`.`order_item_id` FROM `' . $wpdb->prefix . 'woocommerce_order_items` `items` INNER JOIN `' . $wpdb->prefix . "woocommerce_order_itemmeta` `itemmeta` ON `itemmeta`.`order_item_id` = `items`.`order_item_id` AND (`itemmeta`.`meta_key` = '_product_id' OR `itemmeta`.`meta_key` = '_variation_id' ) AND `itemmeta`.`meta_value` = %d WHERE `items`.`order_id` = %d and `items`.`order_item_type` = 'line_item' and `items`.`order_item_id` NOT IN ( '" . implode("','", $item_ids) . "' ) ORDER BY `items`.`order_item_id` ASC", $download->get_product_id(), $download->get_order_id()));
495 if ($item_id) {
496 $items[$download->get_download_id()][] = $item_id;
497 $download_link = add_query_arg(
498 array(
499 'download_file' => $download->get_product_id(),
500 'order' => $download->get_order_key(),
501 'email' => urlencode($download->get_user_email()), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode
502 'key' => $download->get_download_id(),
503 ),
504 trailingslashit(home_url())
505 );
506 $download_links[] = array(
507 's' => $download->get_download_id(),
508 'r' => add_query_arg(array('item_id' => $item_id), $download_link),
509 );
510 }
511 }
512 }
513 }
514 if (!empty($download_links)) {
515 add_action(
516 'admin_print_scripts', function () use ($download_links) {
517 echo '<script>const e2pdf_wc_download_links = ' . wp_json_encode($download_links) . ';document.addEventListener("DOMContentLoaded", function(event) {for (var i = 0; i < e2pdf_wc_download_links.length; i++){var a = document.querySelector(\'a[id="copy-download-link"][href$="\'+e2pdf_wc_download_links[i][\'s\']+\'"]\');if (a) {a.setAttribute(\'href\',e2pdf_wc_download_links[i][\'r\']);}}});</script>';
518 }
519 );
520 }
521 }
522 }
523 }
524
525 public function filter_woocommerce_available_variation($data, $wc_product_variable, $variation) {
526 $description = $variation->get_description();
527 if ($description && false !== strpos($description, '[e2pdf-download') || false !== strpos($description, '[e2pdf-save') || false !== strpos($description, '[e2pdf-view') || false !== strpos($description, '[e2pdf-adobesign') || false !== strpos($description, '[e2pdf-zapier')) {
528 $description = $this->filter_the_content($description, $variation->get_variation_id());
529 $data['variation_description'] = wc_format_content($description);
530 }
531 return $data;
532 }
533
534 public function filter_woocommerce_mail_content($message) {
535 if ($message) {
536 if (false !== strpos($message, '[e2pdf-attachment') || false !== strpos($message, '[e2pdf-save') || false !== strpos($message, '[e2pdf-zapier')) {
537 $message = preg_replace('~(?:\[(e2pdf-attachment|e2pdf-save|e2pdf-zapier)/?)\s[^\]]+/?\]~s', '', $message);
538 }
539 }
540 return $message;
541 }
542
543 public function filter_woocommerce_email_attachments($attachments, $wc_email_id, $order, $wc_email) {
544 if ($wc_email_id == 'ywgc-email-send-gift-card') {
545 $ywgc_gift_post_id = isset($order->ID) ? $order->ID : false;
546 $ywgc_order_item_id = get_post_meta($ywgc_gift_post_id, '_ywgc_order_item_id', true);
547 $order = wc_get_order(isset($order->order_id) ? $order->order_id : false);
548 }
549 if ($order && is_object($order) && method_exists($order, 'get_id') && $wc_email && is_object($wc_email) && method_exists($wc_email, 'get_additional_content')) {
550 if ($wc_email_id == 'ywgc-email-send-gift-card') {
551 $additional_content = isset($wc_email->introductory_text) ? $wc_email->introductory_text : '';
552 $additional_content = str_replace(
553 array(
554 '{recipient_email}',
555 ),
556 array(
557 isset($wc_email->recipient) ? $wc_email->recipient : '',
558 ),
559 $additional_content
560 );
561 } else {
562 $additional_content = $wc_email->get_additional_content();
563 }
564 if (false !== strpos($additional_content, '[')) {
565 $shortcode_tags = array(
566 'e2pdf-attachment',
567 'e2pdf-save',
568 'e2pdf-zapier',
569 );
570 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $additional_content, $matches);
571 $tagnames = array_intersect($shortcode_tags, $matches[1]);
572 if (!empty($tagnames)) {
573 $items = array();
574 $items_variation = array();
575 $items_product = array();
576 if (method_exists($order, 'get_items')) {
577 $order_items = $order->get_items();
578 foreach ($order_items as $item_id => $order_item) {
579 $items[$item_id] = $order_item->get_product_id();
580 if ($order_item->get_variation_id()) {
581 $items_variation[$item_id] = $order_item->get_variation_id();
582 } else {
583 $items_product[$item_id] = $order_item->get_product_id();
584 }
585 }
586 }
587 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $additional_content, $shortcodes);
588 foreach ($shortcodes[0] as $key => $shortcode_value) {
589 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
590 $atts = shortcode_parse_atts($shortcode[3]);
591 $file = false;
592 $template = new Model_E2pdf_Template();
593 if (isset($atts['id']) && $atts['id']) {
594 $template->load($atts['id']);
595 }
596 $attributes = array();
597 foreach ($atts as $att_key => $att) {
598 if (strpos($att_key, 'attribute_') === 0) {
599 $attributes[substr($att_key, 10)] = $att;
600 }
601 }
602 if (isset($atts['product_ids']) && $atts['product_ids']) {
603 $atts['products'] = $atts['product_ids'];
604 }
605 if ($template->get('extension') === 'gravity') {
606 if (!isset($atts['dataset'])) {
607 foreach ($items as $item_id => $item) {
608 $linked_entry_id = false;
609 if ($linked_data = wc_get_order_item_meta($item_id, '_gravity_forms_history', true)) {
610 if (!empty($linked_data['_gravity_form_linked_entry_id'])) {
611 $linked_entry_id = $linked_data['_gravity_form_linked_entry_id'];
612 }
613 } elseif ($linked_data = wc_get_order_item_meta($item_id, 'gspc_gf_entry_ids', true)) {
614 if (!empty($linked_data) && isset($linked_data[0])) {
615 $linked_entry_id = $linked_data[0];
616 }
617 }
618 if ($linked_entry_id) {
619 $attachment = true;
620 if ($attachment) {
621 if (!empty($attributes)) {
622 $product = wc_get_product($item);
623 if ($product) {
624 foreach ($attributes as $attribute_key => $attribute) {
625 if ($product->get_attribute($attribute_key) != $attribute) {
626 $attachment = false;
627 break;
628 }
629 }
630 } else {
631 $attachment = false;
632 }
633 }
634 }
635 if ($attachment) {
636 if (isset($atts['products']) && $atts['products']) {
637 $attachment = false;
638 $products = explode(',', $atts['products']);
639 if (in_array($item, $products, false)) {
640 $attachment = true;
641 } else {
642 $product = wc_get_product($item);
643 if ($product && method_exists($product, 'get_parent_id')) {
644 if (in_array($product->get_parent_id(), $products, false)) {
645 $attachment = true;
646 }
647 }
648 }
649 }
650 }
651 if ($attachment) {
652 if (isset($atts['categories']) && $atts['categories']) {
653 $attachment = false;
654 $categories = explode(',', $atts['categories']);
655 if (has_term($categories, 'product_cat', $item)) {
656 $attachment = true;
657 }
658 }
659 }
660 if ($attachment) {
661 if (isset($atts['tags']) && $atts['tags']) {
662 $attachment = false;
663 $tags = explode(',', $atts['tags']);
664 if (has_term($tags, 'product_tag', $item)) {
665 $attachment = true;
666 }
667 }
668 }
669 if ($attachment) {
670 $item_shortcode = $shortcode;
671 if (!isset($atts['apply'])) {
672 $item_shortcode[3] .= ' apply="true"';
673 }
674 if (!isset($atts['filter'])) {
675 $item_shortcode[3] .= ' filter="true"';
676 }
677 $item_shortcode[3] .= ' dataset="' . $linked_entry_id . '"';
678 if ($this->helper->load('shortcode')->is_attachment($item_shortcode, $atts)) {
679 $file = do_shortcode_tag($item_shortcode);
680 if ($file) {
681 $tmp = false;
682 if (substr($file, 0, 4) === 'tmp:') {
683 $file = substr($file, 4);
684 $tmp = true;
685 }
686 if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
687 if ($tmp) {
688 $this->helper->add('woocommerce_attachments', $file);
689 }
690 } else {
691 $this->helper->add('woocommerce_attachments', $file);
692 }
693 $attachments[] = $file;
694 }
695 } elseif ($item_shortcode[2] === 'e2pdf-zapier' || $item_shortcode[2] === 'e2pdf-save') {
696 do_shortcode_tag($item_shortcode);
697 }
698 }
699 }
700 }
701 }
702 } elseif ($template->get('extension') === 'formidable') {
703 if (!isset($atts['dataset'])) {
704 foreach ($items as $item_id => $item) {
705 $_formidable_form_data = wc_get_order_item_meta($item_id, '_formidable_form_data', true);
706 if ($_formidable_form_data) {
707 $attachment = true;
708 if ($attachment) {
709 if (!empty($attributes)) {
710 $product = wc_get_product($item);
711 if ($product) {
712 foreach ($attributes as $attribute_key => $attribute) {
713 if ($product->get_attribute($attribute_key) != $attribute) {
714 $attachment = false;
715 break;
716 }
717 }
718 } else {
719 $attachment = false;
720 }
721 }
722 }
723 if ($attachment) {
724 if (isset($atts['products']) && $atts['products']) {
725 $attachment = false;
726 $products = explode(',', $atts['products']);
727 if (in_array($item, $products, false)) {
728 $attachment = true;
729 } else {
730 $product = wc_get_product($item);
731 if ($product && method_exists($product, 'get_parent_id')) {
732 if (in_array($product->get_parent_id(), $products, false)) {
733 $attachment = true;
734 }
735 }
736 }
737 }
738 }
739 if ($attachment) {
740 if (isset($atts['categories']) && $atts['categories']) {
741 $attachment = false;
742 $categories = explode(',', $atts['categories']);
743 if (has_term($categories, 'product_cat', $item)) {
744 $attachment = true;
745 }
746 }
747 }
748 if ($attachment) {
749 if (isset($atts['tags']) && $atts['tags']) {
750 $attachment = false;
751 $tags = explode(',', $atts['tags']);
752 if (has_term($tags, 'product_tag', $item)) {
753 $attachment = true;
754 }
755 }
756 }
757 if ($attachment) {
758 $item_shortcode = $shortcode;
759 if (!isset($atts['apply'])) {
760 $item_shortcode[3] .= ' apply="true"';
761 }
762 if (!isset($atts['filter'])) {
763 $item_shortcode[3] .= ' filter="true"';
764 }
765 $item_shortcode[3] .= ' dataset="' . $_formidable_form_data . '"';
766 if ($this->helper->load('shortcode')->is_attachment($item_shortcode, $atts)) {
767 $file = do_shortcode_tag($item_shortcode);
768 if ($file) {
769 $tmp = false;
770 if (substr($file, 0, 4) === 'tmp:') {
771 $file = substr($file, 4);
772 $tmp = true;
773 }
774 if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
775 if ($tmp) {
776 $this->helper->add('woocommerce_attachments', $file);
777 }
778 } else {
779 $this->helper->add('woocommerce_attachments', $file);
780 }
781 $attachments[] = $file;
782 }
783 } elseif ($item_shortcode[2] === 'e2pdf-zapier' || $item_shortcode[2] === 'e2pdf-save') {
784 do_shortcode_tag($item_shortcode);
785 }
786 }
787 }
788 }
789 }
790 } elseif ($wc_email_id == 'ywgc-email-send-gift-card' && $template->get('extension') === 'wordpress') { // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
791 if ($template->get('item') == 'gift_card') {
792 if (isset($atts['dataset'])) {
793 foreach ($items_product as $item_id => $item) {
794 if ($ywgc_order_item_id != $item_id) {
795 continue;
796 }
797 if ($item == $atts['dataset']) {
798 $attachment = true;
799 if ($attachment) {
800 if (!empty($attributes)) {
801 $product = wc_get_product($item);
802 if ($product) {
803 foreach ($attributes as $attribute_key => $attribute) {
804 if ($product->get_attribute($attribute_key) != $attribute) {
805 $attachment = false;
806 break;
807 }
808 }
809 } else {
810 $attachment = false;
811 }
812 }
813 }
814 if ($attachment) {
815 $item_shortcode = $shortcode;
816 if (!isset($atts['apply'])) {
817 $item_shortcode[3] .= ' apply="true"';
818 }
819 if (!isset($atts['filter'])) {
820 $item_shortcode[3] .= ' filter="true"';
821 }
822 $item_shortcode[3] .= ' dataset="' . $ywgc_gift_post_id . '"';
823 if ($this->helper->load('shortcode')->is_attachment($item_shortcode, $atts)) {
824 $file = do_shortcode_tag($item_shortcode);
825 if ($file) {
826 $tmp = false;
827 if (substr($file, 0, 4) === 'tmp:') {
828 $file = substr($file, 4);
829 $tmp = true;
830 }
831 if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
832 if ($tmp) {
833 $file = substr($file, 4);
834 $this->helper->add('woocommerce_attachments', $file);
835 }
836 } else {
837 $this->helper->add('woocommerce_attachments', $file);
838 }
839 $attachments[] = $file;
840 }
841 } elseif ($item_shortcode[2] === 'e2pdf-zapier' || $item_shortcode[2] === 'e2pdf-save') {
842 do_shortcode_tag($item_shortcode);
843 }
844 }
845 }
846 }
847 } elseif (!isset($atts['dataset'])) {
848 foreach ($items_product as $item_id => $item) {
849 if ($ywgc_order_item_id != $item_id) {
850 continue;
851 }
852 $attachment = true;
853 if ($attachment) {
854 if (!empty($attributes)) {
855 $product = wc_get_product($item);
856 if ($product) {
857 foreach ($attributes as $attribute_key => $attribute) {
858 if ($product->get_attribute($attribute_key) != $attribute) {
859 $attachment = false;
860 break;
861 }
862 }
863 } else {
864 $attachment = false;
865 }
866 }
867 }
868 if ($attachment) {
869 if (isset($atts['products']) && $atts['products']) {
870 $attachment = false;
871 $products = explode(',', $atts['products']);
872 if (in_array($item, $products, false)) {
873 $attachment = true;
874 }
875 }
876 }
877 if ($attachment) {
878 if (isset($atts['categories']) && $atts['categories']) {
879 $attachment = false;
880 $categories = explode(',', $atts['categories']);
881 if (has_term($categories, 'product_cat', $item)) {
882 $attachment = true;
883 }
884 }
885 }
886 if ($attachment) {
887 if (isset($atts['tags']) && $atts['tags']) {
888 $attachment = false;
889 $tags = explode(',', $atts['tags']);
890 if (has_term($tags, 'product_tag', $item)) {
891 $attachment = true;
892 }
893 }
894 }
895 if ($attachment) {
896 $item_shortcode = $shortcode;
897 if (!isset($atts['apply'])) {
898 $item_shortcode[3] .= ' apply="true"';
899 }
900 if (!isset($atts['filter'])) {
901 $item_shortcode[3] .= ' filter="true"';
902 }
903 $item_shortcode[3] .= ' dataset="' . $ywgc_gift_post_id . '"';
904 if ($this->helper->load('shortcode')->is_attachment($item_shortcode, $atts)) {
905 $file = do_shortcode_tag($item_shortcode);
906 if ($file) {
907 $tmp = false;
908 if (substr($file, 0, 4) === 'tmp:') {
909 $file = substr($file, 4);
910 $tmp = true;
911 }
912 if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
913 if ($tmp) {
914 $this->helper->add('woocommerce_attachments', $file);
915 }
916 } else {
917 $this->helper->add('woocommerce_attachments', $file);
918 }
919 $attachments[] = $file;
920 }
921 } elseif ($item_shortcode[2] === 'e2pdf-zapier' || $item_shortcode[2] === 'e2pdf-save') {
922 do_shortcode_tag($item_shortcode);
923 }
924 }
925 }
926 }
927 }
928 } elseif ($template->get('extension') === 'woocommerce') {
929 if ($template->get('item') == 'product') {
930 if (isset($atts['dataset'])) {
931 foreach ($items_product as $item_id => $item) {
932 if ($wc_email_id == 'ywgc-email-send-gift-card' && $ywgc_order_item_id != $item_id) {
933 continue;
934 }
935 if ($item == $atts['dataset']) {
936 $attachment = true;
937 if ($attachment) {
938 if (!empty($attributes)) {
939 $product = wc_get_product($item);
940 if ($product) {
941 foreach ($attributes as $attribute_key => $attribute) {
942 if ($product->get_attribute($attribute_key) != $attribute) {
943 $attachment = false;
944 break;
945 }
946 }
947 } else {
948 $attachment = false;
949 }
950 }
951 }
952 if ($attachment) {
953 $item_shortcode = $shortcode;
954 if (!isset($atts['apply'])) {
955 $item_shortcode[3] .= ' apply="true"';
956 }
957 if (!isset($atts['filter'])) {
958 $item_shortcode[3] .= ' filter="true"';
959 }
960 if (!isset($atts['wc_order_id'])) {
961 $item_shortcode[3] .= ' wc_order_id="' . $order->get_id() . '"';
962 }
963 if (!isset($atts['wc_product_item_id'])) {
964 $item_shortcode[3] .= ' wc_product_item_id="' . $item_id . '"';
965 }
966
967 if ($this->helper->load('shortcode')->is_attachment($item_shortcode, $atts)) {
968 $file = do_shortcode_tag($item_shortcode);
969 if ($file) {
970 $tmp = false;
971 if (substr($file, 0, 4) === 'tmp:') {
972 $file = substr($file, 4);
973 $tmp = true;
974 }
975 if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
976 if ($tmp) {
977 $file = substr($file, 4);
978 $this->helper->add('woocommerce_attachments', $file);
979 }
980 } else {
981 $this->helper->add('woocommerce_attachments', $file);
982 }
983 $attachments[] = $file;
984 }
985 } elseif ($item_shortcode[2] === 'e2pdf-zapier' || $item_shortcode[2] === 'e2pdf-save') {
986 do_shortcode_tag($item_shortcode);
987 }
988 }
989 }
990 }
991 } elseif (!isset($atts['dataset'])) {
992 foreach ($items_product as $item_id => $item) {
993 if ($wc_email_id == 'ywgc-email-send-gift-card' && $ywgc_order_item_id != $item_id) {
994 continue;
995 }
996 $attachment = true;
997 if ($attachment) {
998 if (!empty($attributes)) {
999 $product = wc_get_product($item);
1000 if ($product) {
1001 foreach ($attributes as $attribute_key => $attribute) {
1002 if ($product->get_attribute($attribute_key) != $attribute) {
1003 $attachment = false;
1004 break;
1005 }
1006 }
1007 } else {
1008 $attachment = false;
1009 }
1010 }
1011 }
1012 if ($attachment) {
1013 if (isset($atts['products']) && $atts['products']) {
1014 $attachment = false;
1015 $products = explode(',', $atts['products']);
1016 if (in_array($item, $products, false)) {
1017 $attachment = true;
1018 }
1019 }
1020 }
1021 if ($attachment) {
1022 if (isset($atts['categories']) && $atts['categories']) {
1023 $attachment = false;
1024 $categories = explode(',', $atts['categories']);
1025 if (has_term($categories, 'product_cat', $item)) {
1026 $attachment = true;
1027 }
1028 }
1029 }
1030 if ($attachment) {
1031 if (isset($atts['tags']) && $atts['tags']) {
1032 $attachment = false;
1033 $tags = explode(',', $atts['tags']);
1034 if (has_term($tags, 'product_tag', $item)) {
1035 $attachment = true;
1036 }
1037 }
1038 }
1039 if ($attachment) {
1040 $item_shortcode = $shortcode;
1041 if (!isset($atts['apply'])) {
1042 $item_shortcode[3] .= ' apply="true"';
1043 }
1044 if (!isset($atts['filter'])) {
1045 $item_shortcode[3] .= ' filter="true"';
1046 }
1047 if (!isset($atts['wc_order_id'])) {
1048 $item_shortcode[3] .= ' wc_order_id="' . $order->get_id() . '"';
1049 }
1050 if (!isset($atts['wc_product_item_id'])) {
1051 $item_shortcode[3] .= ' wc_product_item_id="' . $item_id . '"';
1052 }
1053 $item_shortcode[3] .= ' dataset="' . $item . '"';
1054 if ($this->helper->load('shortcode')->is_attachment($item_shortcode, $atts)) {
1055 $file = do_shortcode_tag($item_shortcode);
1056 if ($file) {
1057 $tmp = false;
1058 if (substr($file, 0, 4) === 'tmp:') {
1059 $file = substr($file, 4);
1060 $tmp = true;
1061 }
1062 if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
1063 if ($tmp) {
1064 $this->helper->add('woocommerce_attachments', $file);
1065 }
1066 } else {
1067 $this->helper->add('woocommerce_attachments', $file);
1068 }
1069 $attachments[] = $file;
1070 }
1071 } elseif ($item_shortcode[2] === 'e2pdf-zapier' || $item_shortcode[2] === 'e2pdf-save') {
1072 do_shortcode_tag($item_shortcode);
1073 }
1074 }
1075 }
1076 }
1077 } elseif ($template->get('item') == 'product_variation') {
1078 if (isset($atts['dataset'])) {
1079 foreach ($items_variation as $item_id => $item) {
1080 if ($item == $atts['dataset']) {
1081 $attachment = true;
1082 if ($attachment) {
1083 if (!empty($attributes)) {
1084 $product = wc_get_product($item);
1085 if ($product) {
1086 foreach ($attributes as $attribute_key => $attribute) {
1087 if ($product->get_attribute($attribute_key) != $attribute) {
1088 $attachment = false;
1089 break;
1090 }
1091 }
1092 } else {
1093 $attachment = false;
1094 }
1095 }
1096 }
1097 if ($attachment) {
1098 $item_shortcode = $shortcode;
1099 if (!isset($atts['apply'])) {
1100 $item_shortcode[3] .= ' apply="true"';
1101 }
1102 if (!isset($atts['filter'])) {
1103 $item_shortcode[3] .= ' filter="true"';
1104 }
1105 if (!isset($atts['wc_order_id'])) {
1106 $item_shortcode[3] .= ' wc_order_id="' . $order->get_id() . '"';
1107 }
1108 if (!isset($atts['wc_product_item_id'])) {
1109 $item_shortcode[3] .= ' wc_product_item_id="' . $item_id . '"';
1110 }
1111 if ($this->helper->load('shortcode')->is_attachment($item_shortcode, $atts)) {
1112 $file = do_shortcode_tag($item_shortcode);
1113 if ($file) {
1114 $tmp = false;
1115 if (substr($file, 0, 4) === 'tmp:') {
1116 $file = substr($file, 4);
1117 $tmp = true;
1118 }
1119 if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
1120 if ($tmp) {
1121 $this->helper->add('woocommerce_attachments', $file);
1122 }
1123 } else {
1124 $this->helper->add('woocommerce_attachments', $file);
1125 }
1126 $attachments[] = $file;
1127 }
1128 } elseif ($item_shortcode[2] === 'e2pdf-zapier' || $item_shortcode[2] === 'e2pdf-save') {
1129 do_shortcode_tag($item_shortcode);
1130 }
1131 }
1132 }
1133 }
1134 } elseif (!isset($atts['dataset'])) {
1135 foreach ($items_variation as $item_id => $item) {
1136 $attachment = true;
1137 if ($attachment) {
1138 if (!empty($attributes)) {
1139 $product = wc_get_product($item);
1140 if ($product) {
1141 foreach ($attributes as $attribute_key => $attribute) {
1142 if ($product->get_attribute($attribute_key) != $attribute) {
1143 $attachment = false;
1144 break;
1145 }
1146 }
1147 } else {
1148 $attachment = false;
1149 }
1150 }
1151 }
1152 if ($attachment) {
1153 if (isset($atts['products']) && $atts['products']) {
1154 $attachment = false;
1155 $products = explode(',', $atts['products']);
1156 if (in_array($item, $products, false)) {
1157 $attachment = true;
1158 } else {
1159 $product = wc_get_product($item);
1160 if ($product && method_exists($product, 'get_parent_id')) {
1161 if (in_array($product->get_parent_id(), $products, false)) {
1162 $attachment = true;
1163 }
1164 }
1165 }
1166 }
1167 }
1168 if ($attachment) {
1169 if (isset($atts['categories']) && $atts['categories']) {
1170 $attachment = false;
1171 $categories = explode(',', $atts['categories']);
1172 if (has_term($categories, 'product_cat', $item)) {
1173 $attachment = true;
1174 }
1175 }
1176 }
1177 if ($attachment) {
1178 if (isset($atts['tags']) && $atts['tags']) {
1179 $attachment = false;
1180 $tags = explode(',', $atts['tags']);
1181 if (has_term($tags, 'product_tag', $item)) {
1182 $attachment = true;
1183 }
1184 }
1185 }
1186 if ($attachment) {
1187 $item_shortcode = $shortcode;
1188 if (!isset($atts['apply'])) {
1189 $item_shortcode[3] .= ' apply="true"';
1190 }
1191 if (!isset($atts['filter'])) {
1192 $item_shortcode[3] .= ' filter="true"';
1193 }
1194 if (!isset($atts['wc_order_id'])) {
1195 $item_shortcode[3] .= ' wc_order_id="' . $order->get_id() . '"';
1196 }
1197 if (!isset($atts['wc_product_item_id'])) {
1198 $item_shortcode[3] .= ' wc_product_item_id="' . $item_id . '"';
1199 }
1200 $item_shortcode[3] .= ' dataset="' . $item . '"';
1201 if ($this->helper->load('shortcode')->is_attachment($item_shortcode, $atts)) {
1202 $file = do_shortcode_tag($item_shortcode);
1203 if ($file) {
1204 $tmp = false;
1205 if (substr($file, 0, 4) === 'tmp:') {
1206 $file = substr($file, 4);
1207 $tmp = true;
1208 }
1209 if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
1210 if ($tmp) {
1211 $this->helper->add('woocommerce_attachments', $file);
1212 }
1213 } else {
1214 $this->helper->add('woocommerce_attachments', $file);
1215 }
1216 $attachments[] = $file;
1217 }
1218 } elseif ($item_shortcode[2] === 'e2pdf-zapier' || $item_shortcode[2] === 'e2pdf-save') {
1219 do_shortcode_tag($item_shortcode);
1220 }
1221 }
1222 }
1223 }
1224 } elseif ($template->get('item') == 'shop_subscription' && function_exists('wcs_get_subscriptions_for_order')) {
1225 $subscriptions = wcs_get_subscriptions_for_order($order->get_id());
1226 foreach ($subscriptions as $subscription) {
1227 if (!isset($atts['dataset'])) {
1228 $attachment = true;
1229 if ($attachment) {
1230 if (!empty($attributes)) {
1231 $attachment = false;
1232 foreach ($items_product as $item_id => $item) {
1233 $product = wc_get_product($item);
1234 if ($product) {
1235 foreach ($attributes as $attribute_key => $attribute) {
1236 if ($product->get_attribute($attribute_key) != $attribute) {
1237 $attachment = true;
1238 break;
1239 }
1240 }
1241 }
1242 }
1243 if (!$attachment) {
1244 foreach ($items_variation as $item_id => $item) {
1245 $product = wc_get_product($item);
1246 if ($product) {
1247 foreach ($attributes as $attribute_key => $attribute) {
1248 if ($product->get_attribute($attribute_key) == $attribute) {
1249 $attachment = true;
1250 break;
1251 }
1252 }
1253 }
1254 }
1255 }
1256 }
1257 }
1258 if ($attachment) {
1259 if (isset($atts['products']) && $atts['products']) {
1260 $attachment = false;
1261 $products = explode(',', $atts['products']);
1262 foreach ($products as $product_id) {
1263 if (in_array($product_id, $items, false) || in_array($product_id, $items_variation, false)) {
1264 $attachment = true;
1265 break;
1266 }
1267 }
1268 }
1269 }
1270 if ($attachment) {
1271 if (isset($atts['categories']) && $atts['categories']) {
1272 $attachment = false;
1273 $categories = explode(',', $atts['categories']);
1274 foreach ($items as $item) {
1275 if (has_term($categories, 'product_cat', $item)) {
1276 $attachment = true;
1277 break;
1278 }
1279 }
1280 }
1281 }
1282 if ($attachment) {
1283 if (isset($atts['tags']) && $atts['tags']) {
1284 $attachment = false;
1285 $tags = explode(',', $atts['tags']);
1286 foreach ($items as $item) {
1287 if (has_term($tags, 'product_tag', $item)) {
1288 $attachment = true;
1289 break;
1290 }
1291 }
1292 }
1293 }
1294 if ($attachment) {
1295 if (!isset($atts['apply'])) {
1296 $shortcode[3] .= ' apply="true"';
1297 }
1298 if (!isset($atts['filter'])) {
1299 $shortcode[3] .= ' filter="true"';
1300 }
1301 $shortcode[3] .= ' dataset="' . $subscription->get_id() . '"';
1302 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) {
1303 $file = do_shortcode_tag($shortcode);
1304 if ($file) {
1305 $tmp = false;
1306 if (substr($file, 0, 4) === 'tmp:') {
1307 $file = substr($file, 4);
1308 $tmp = true;
1309 }
1310 if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
1311 if ($tmp) {
1312 $this->helper->add('woocommerce_attachments', $file);
1313 }
1314 } else {
1315 $this->helper->add('woocommerce_attachments', $file);
1316 }
1317 $attachments[] = $file;
1318 }
1319 } elseif ($shortcode[2] === 'e2pdf-zapier' || $shortcode[2] === 'e2pdf-save') {
1320 do_shortcode_tag($shortcode);
1321 }
1322 }
1323 }
1324 }
1325 } elseif ($template->get('item') == 'shop_order') {
1326 if (!isset($atts['dataset'])) {
1327 $attachment = true;
1328 if ($attachment) {
1329 if (!empty($attributes)) {
1330 $attachment = false;
1331 foreach ($items_product as $item_id => $item) {
1332 $product = wc_get_product($item);
1333 if ($product) {
1334 foreach ($attributes as $attribute_key => $attribute) {
1335 if ($product->get_attribute($attribute_key) != $attribute) {
1336 $attachment = true;
1337 break;
1338 }
1339 }
1340 }
1341 }
1342 if (!$attachment) {
1343 foreach ($items_variation as $item_id => $item) {
1344 $product = wc_get_product($item);
1345 if ($product) {
1346 foreach ($attributes as $attribute_key => $attribute) {
1347 if ($product->get_attribute($attribute_key) == $attribute) {
1348 $attachment = true;
1349 break;
1350 }
1351 }
1352 }
1353 }
1354 }
1355 }
1356 }
1357 if ($attachment) {
1358 if (isset($atts['products']) && $atts['products']) {
1359 $attachment = false;
1360 $products = explode(',', $atts['products']);
1361 foreach ($products as $product_id) {
1362 if (in_array($product_id, $items, false) || in_array($product_id, $items_variation, false)) {
1363 $attachment = true;
1364 break;
1365 }
1366 }
1367 }
1368 }
1369 if ($attachment) {
1370 if (isset($atts['categories']) && $atts['categories']) {
1371 $attachment = false;
1372 $categories = explode(',', $atts['categories']);
1373 foreach ($items as $item) {
1374 if (has_term($categories, 'product_cat', $item)) {
1375 $attachment = true;
1376 break;
1377 }
1378 }
1379 }
1380 }
1381 if ($attachment) {
1382 if (isset($atts['tags']) && $atts['tags']) {
1383 $attachment = false;
1384 $tags = explode(',', $atts['tags']);
1385 foreach ($items as $item) {
1386 if (has_term($tags, 'product_tag', $item)) {
1387 $attachment = true;
1388 break;
1389 }
1390 }
1391 }
1392 }
1393 if ($attachment) {
1394 if (!isset($atts['apply'])) {
1395 $shortcode[3] .= ' apply="true"';
1396 }
1397 if (!isset($atts['filter'])) {
1398 $shortcode[3] .= ' filter="true"';
1399 }
1400 $shortcode[3] .= ' dataset="' . $order->get_id() . '"';
1401 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) {
1402 $file = do_shortcode_tag($shortcode);
1403 if ($file) {
1404 $tmp = false;
1405 if (substr($file, 0, 4) === 'tmp:') {
1406 $file = substr($file, 4);
1407 $tmp = true;
1408 }
1409 if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
1410 if ($tmp) {
1411 $this->helper->add('woocommerce_attachments', $file);
1412 }
1413 } else {
1414 $this->helper->add('woocommerce_attachments', $file);
1415 }
1416 $attachments[] = $file;
1417 }
1418 } elseif ($shortcode[2] === 'e2pdf-zapier' || $shortcode[2] === 'e2pdf-save') {
1419 do_shortcode_tag($shortcode);
1420 }
1421 }
1422 }
1423 }
1424 }
1425 }
1426 }
1427 }
1428 }
1429 return $attachments;
1430 }
1431
1432 public function filter_gform_merge_tag_filter($value, $merge_tag, $modifier, $field, $raw_value) {
1433
1434 if ($field && $value) {
1435 if ($field->type == 'consent') {
1436 if (false !== strpos($modifier, 'filter') && is_callable('gw_all_fields_template')) {
1437 $modifiers = gw_all_fields_template()->parse_modifiers($modifier);
1438 if (isset($modifiers['filter']) && $modifiers['filter'] && !is_array($modifiers['filter'])) {
1439 $merge_tag = $modifiers['filter'];
1440 }
1441 }
1442 $mod = explode('.', $merge_tag);
1443 if (isset($mod[1]) && $mod[1] == '1') {
1444 $value = '1';
1445 }
1446 } elseif ($field->type == 'list') {
1447 if (false !== strpos($modifier, 'filter') && is_callable('gw_all_fields_template')) {
1448 $modifiers = gw_all_fields_template()->parse_modifiers($modifier);
1449 if (isset($modifiers['filter']) && $modifiers['filter'] && !is_array($modifiers['filter'])) {
1450 if (false !== strpos($modifiers['filter'], ':')) {
1451 $mods = explode(':', $modifiers['filter']);
1452 $merge_tag = $mods[0];
1453 $modifier = $mods[1];
1454 } else {
1455 $merge_tag = $modifiers['filter'];
1456 }
1457 }
1458 if ($merge_tag != $field->id) {
1459 return false;
1460 }
1461 }
1462 if ($modifier && $modifier != 'text') {
1463 $list_id = false;
1464 $field_id = false;
1465 if (false !== strpos($modifier, '_')) {
1466 $mod = explode('_', $modifier);
1467 if (isset($mod[0]) && is_numeric($mod[0])) {
1468 $list_id = $mod[0] - 1;
1469 }
1470 if (isset($mod[1]) && is_numeric($mod[1])) {
1471 $field_id = $mod[1] - 1;
1472 }
1473 } elseif (is_numeric($modifier)) {
1474 $list_id = $modifier - 1;
1475 }
1476 if ($list_id !== false) {
1477 $value = '';
1478 if (is_serialized($raw_value)) {
1479 $list = $this->helper->load('convert')->unserialize(trim($raw_value));
1480 } else {
1481 $list = $raw_value;
1482 }
1483 if (is_array($list)) {
1484 if (isset($list[$list_id])) {
1485 if ($field_id !== false) {
1486 if (is_array($list[$list_id]) && isset(array_values($list[$list_id])[$field_id])) {
1487 $value = array_values($list[$list_id])[$field_id];
1488 }
1489 } else {
1490 if (is_array($list[$list_id])) {
1491 $value = implode(',', $list[$list_id]);
1492 } else {
1493 $value = $list[$list_id];
1494 }
1495 }
1496 }
1497 }
1498 }
1499 }
1500 } elseif ($field->type == 'name' || $field->type == 'address') {
1501 if (false !== strpos($modifier, 'filter') && is_callable('gw_all_fields_template')) {
1502 $modifiers = gw_all_fields_template()->parse_modifiers($modifier);
1503 if (isset($modifiers['filter']) && $modifiers['filter'] && !is_array($modifiers['filter'])) {
1504 if (is_array($raw_value) && isset($raw_value[$modifiers['filter']])) {
1505 return $raw_value[$modifiers['filter']];
1506 }
1507 }
1508 }
1509 }
1510 }
1511
1512 return $value;
1513 }
1514
1515 public function filter_woocommerce_display_product_attributes($product_attributes, $product) {
1516 if ($product_attributes) {
1517 foreach ($product_attributes as $product_attribute_key => $product_attribute) {
1518 if (isset($product_attribute['value']) && $product_attribute['value'] && false !== strpos($product_attribute['value'], '[e2pdf-download')) {
1519 $product_attributes[$product_attribute_key]['value'] = $this->filter_content(htmlspecialchars_decode($product_attribute['value']), $product->get_id());
1520 }
1521 }
1522 }
1523 return $product_attributes;
1524 }
1525
1526 public function filter_e2pdf_model_shortcode_wc_product_get_attribute_value($product_attribute, $product) {
1527 if ($product_attribute && false !== strpos($product_attribute, '[e2pdf-download') && $product && is_object($product) && method_exists($product, 'get_id')) {
1528 $product_attribute = $this->filter_content(htmlspecialchars_decode($product_attribute), $product->get_id());
1529 }
1530 return $product_attribute;
1531 }
1532
1533 public function filter_woocommerce_product_file_download_path($file_path, $product, $download_id) {
1534 $file_path = $this->filter_content($file_path, $product->get_id(), true);
1535 return $file_path;
1536 }
1537
1538 public function filter_download_urls($downloads) {
1539 if (!empty($downloads)) {
1540 $items = array();
1541 foreach ($downloads as $key => $download) {
1542 if (isset($download['file']['file']) && $download['file']['file'] && strpos($download['file']['file'], '[e2pdf-download') !== false) {
1543 global $wpdb;
1544 if (isset($items[$download['download_id']])) {
1545 $item_ids = $items[$download['download_id']];
1546 } else {
1547 $item_ids = array();
1548 }
1549 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
1550 $item_id = $wpdb->get_var($wpdb->prepare('SELECT `items`.`order_item_id` FROM `' . $wpdb->prefix . 'woocommerce_order_items` `items` INNER JOIN `' . $wpdb->prefix . "woocommerce_order_itemmeta` `itemmeta` ON `itemmeta`.`order_item_id` = `items`.`order_item_id` AND (`itemmeta`.`meta_key` = '_product_id' OR `itemmeta`.`meta_key` = '_variation_id' ) AND `itemmeta`.`meta_value` = %d WHERE `items`.`order_id` = %d and `items`.`order_item_type` = 'line_item' and `items`.`order_item_id` NOT IN ( '" . implode("','", $item_ids) . "' ) ORDER BY `items`.`order_item_id` ASC", $download['product_id'], $download['order_id']));
1551 if ($item_id) {
1552 $downloads[$key]['download_url'] = add_query_arg(
1553 array('item_id' => $item_id), $download['download_url']
1554 );
1555 $items[$download['download_id']][] = $item_id;
1556 }
1557 }
1558 }
1559 }
1560 return $downloads;
1561 }
1562
1563 /**
1564 * Render value according to content
1565 * @param string $value - Content
1566 * @param string $type - Type of rendering value
1567 * @param array $field - Field details
1568 * @return string - Fully rendered value
1569 */
1570 public function render($value, $field = array(), $convert_shortcodes = true, $raw = false) {
1571 $value = $this->render_shortcodes($value, $field);
1572 if (!$raw) {
1573 $value = $this->strip_shortcodes($value);
1574 $value = $this->convert_shortcodes($value, $convert_shortcodes, isset($field['type']) && $field['type'] == 'e2pdf-html' ? true : false);
1575 $value = $this->helper->load('field')->render_checkbox($value, $this, $field);
1576 }
1577 return $value;
1578 }
1579
1580 /**
1581 * Render shortcodes which available in this extension
1582 * @param string $value - Content
1583 * @param string $type - Type of rendering value
1584 * @param array $field - Field details
1585 * @return string - Value with rendered shortcodes
1586 */
1587 public function render_shortcodes($value, $field = array()) {
1588 $element_id = isset($field['element_id']) ? $field['element_id'] : false;
1589 if ($this->verify()) {
1590 if (false !== strpos($value, '[')) {
1591 $value = $this->helper->load('field')->pre_shortcodes($value, $this, $field);
1592 $value = $this->helper->load('field')->inner_shortcodes($value, $this, $field);
1593 $shortcode_tags = array(
1594 'e2pdf-wc-product',
1595 'e2pdf-wc-order',
1596 'e2pdf-wc-cart',
1597 'e2pdf-content',
1598 'e2pdf-wp',
1599 'acf',
1600 );
1601 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches);
1602 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1603 foreach ($matches[1] as $key => $shortcode) {
1604 if (strpos($shortcode, ':') !== false) {
1605 $shortcode_tags[] = $shortcode;
1606 }
1607 }
1608 if (!empty($tagnames)) {
1609 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $value, $shortcodes);
1610 foreach ($shortcodes[0] as $key => $shortcode_value) {
1611 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
1612 $atts = shortcode_parse_atts($shortcode[3]);
1613 if ($shortcode[2] === 'e2pdf-wp') {
1614 if (isset($atts['id']) && $atts['id'] == 'dynamic' && substr($shortcode_value, -11) === '[/e2pdf-wp]') {
1615 if ($shortcode[5]) {
1616 $shortcode[5] = $this->render($shortcode[5], array(), false);
1617 }
1618 $value = str_replace($shortcode_value, '[e2pdf-wp' . $shortcode[3] . ']' . $shortcode[5] . '[/e2pdf-wp]', $value);
1619 }
1620 } elseif ($shortcode[2] == 'e2pdf-wc-product') {
1621 switch ($this->get('item')) {
1622 case 'product':
1623 case 'product_variation':
1624 if (!isset($atts['id']) && !isset($atts['index']) && isset($this->get('cached_post')->ID) && $this->get('cached_post')->ID) {
1625 $shortcode[3] .= ' id=' . $this->get('cached_post')->ID . '';
1626 }
1627 if (!isset($atts['wc_order_id']) && $this->get('wc_order_id')) {
1628 $shortcode[3] .= ' wc_order_id=' . $this->get('wc_order_id') . '';
1629 }
1630
1631 if (!isset($atts['wc_product_item_id']) && $this->get('wc_product_item_id')) {
1632 $shortcode[3] .= ' wc_product_item_id=' . $this->get('wc_product_item_id') . '';
1633 }
1634 break;
1635 case 'shop_order':
1636 case 'shop_subscription':
1637 if (!isset($atts['wc_order_id']) && isset($this->get('cached_post')->ID) && $this->get('cached_post')->ID) {
1638 $shortcode[3] .= ' wc_order_id=' . $this->get('cached_post')->ID . '';
1639 }
1640 break;
1641 case 'cart':
1642 $shortcode[3] .= ' wc_order_id=cart';
1643 break;
1644 default:
1645 break;
1646 }
1647
1648 if (isset($atts['id']) && $atts['id'] == 'dynamic' && substr($shortcode_value, -19) === '[/e2pdf-wc-product]') {
1649 if ($shortcode[5]) {
1650 $shortcode[5] = $this->render($shortcode[5], array(), false);
1651 }
1652 $value = str_replace($shortcode_value, '[e2pdf-wc-product' . $shortcode[3] . ']' . $shortcode[5] . '[/e2pdf-wc-product]', $value);
1653 } else {
1654 $value = str_replace($shortcode_value, '[e2pdf-wc-product' . $shortcode[3] . ']', $value);
1655 }
1656 } elseif ($shortcode[2] == 'e2pdf-wc-order') {
1657 switch ($this->get('item')) {
1658 case 'product':
1659 case 'product_variation':
1660 if (!isset($atts['id']) && $this->get('wc_order_id')) {
1661 $shortcode[3] .= ' id=' . $this->get('wc_order_id') . '';
1662 }
1663 break;
1664 case 'shop_order':
1665 case 'shop_subscription':
1666 if (!isset($atts['id']) && isset($this->get('cached_post')->ID) && $this->get('cached_post')->ID) {
1667 $shortcode[3] .= ' id=' . $this->get('cached_post')->ID . '';
1668 }
1669 break;
1670 default:
1671 break;
1672 }
1673 if (isset($atts['id']) && $atts['id'] == 'dynamic' && substr($shortcode_value, -17) === '[/e2pdf-wc-order]') {
1674 if ($shortcode[5]) {
1675 $shortcode[5] = $this->render($shortcode[5], array(), false);
1676 }
1677 $value = str_replace($shortcode_value, '[e2pdf-wc-order' . $shortcode[3] . ']' . $shortcode[5] . '[/e2pdf-wc-order]', $value);
1678 } else {
1679 $value = str_replace($shortcode_value, '[e2pdf-wc-order' . $shortcode[3] . ']', $value);
1680 }
1681 } elseif ($shortcode[2] == 'e2pdf-wc-cart') {
1682 if ($this->get('item') == 'cart') {
1683 if (!isset($atts['id']) && isset($this->get('cached_post')->ID) && $this->get('cached_post')->ID) {
1684 $shortcode[3] .= ' id=' . $this->get('cached_post')->ID . '';
1685 }
1686 $value = str_replace($shortcode_value, '[e2pdf-wc-cart' . $shortcode[3] . ']', $value);
1687 }
1688 } elseif ($shortcode[2] === 'acf') {
1689 if (!isset($atts['post_id']) && isset($this->get('cached_post')->ID) && $this->get('cached_post')->ID) {
1690 if ($this->get('item') == 'product_variation' && isset($this->get('cached_post')->post_parent)) {
1691 $shortcode[3] .= ' post_id=' . $this->get('cached_post')->post_parent . '';
1692 } else {
1693 $shortcode[3] .= ' post_id=' . $this->get('cached_post')->ID . '';
1694 }
1695 $value = str_replace($shortcode_value, '[' . $shortcode[2] . $shortcode[3] . ']', $value);
1696 }
1697 }
1698 }
1699 }
1700 $value = $this->helper->load('field')->wrapper_shortcodes($value, $this, $field);
1701 }
1702 $value = $this->helper->load('field')->do_shortcodes($value, $this, $field);
1703
1704 /* Process Gravity Forms Connected Entry */
1705 if (false !== strpos($value, '{') && class_exists('GFCommon') && class_exists('GFFormsModel')) {
1706 if (($this->get('item') == 'product' || $this->get('item') == 'product_variation') && $this->get('wc_order_id')) {
1707 $order = wc_get_order($this->get('wc_order_id'));
1708 if ($order && method_exists($order, 'get_items')) {
1709 $order_items = $order->get_items();
1710 $linked_entry_id = false;
1711 if ($this->get('wc_product_item_id')) {
1712 $item_id = $this->get('wc_product_item_id');
1713 if (isset($order_items[$item_id])) {
1714 if ($linked_data = wc_get_order_item_meta($item_id, '_gravity_forms_history', true)) {
1715 if (!empty($linked_data['_gravity_form_linked_entry_id'])) {
1716 $linked_entry_id = $linked_data['_gravity_form_linked_entry_id'];
1717 }
1718 } elseif ($linked_data = wc_get_order_item_meta($item_id, 'gspc_gf_entry_ids', true)) {
1719 if (!empty($linked_data) && isset($linked_data[0])) {
1720 $linked_entry_id = $linked_data[0];
1721 }
1722 }
1723 }
1724 } else {
1725 foreach ($order_items as $item_id => $order_item) {
1726 if ($order_item->get_product_id() == $this->get('dataset')) {
1727 if ($linked_data = wc_get_order_item_meta($item_id, '_gravity_forms_history', true)) {
1728 if (!empty($linked_data['_gravity_form_linked_entry_id'])) {
1729 $linked_entry_id = $linked_data['_gravity_form_linked_entry_id'];
1730 }
1731 } elseif ($linked_data = wc_get_order_item_meta($item_id, 'gspc_gf_entry_ids', true)) {
1732 if (!empty($linked_data) && isset($linked_data[0])) {
1733 $linked_entry_id = $linked_data[0];
1734 }
1735 }
1736 }
1737 }
1738 }
1739
1740 if ($linked_entry_id) {
1741 $entry = GFFormsModel::get_entry($linked_entry_id);
1742 if ($entry && isset($entry['form_id'])) {
1743 $form = GFFormsModel::get_form_meta($entry['form_id']);
1744 add_filter('gform_merge_tag_filter', array($this, 'filter_gform_merge_tag_filter'), 30, 5);
1745 $value = GFCommon::replace_variables($value, $form, $entry, false, false, false, 'text');
1746 remove_filter('gform_merge_tag_filter', array($this, 'filter_gform_merge_tag_filter'), 30, 5);
1747 }
1748 }
1749 }
1750 }
1751 }
1752
1753 $value = $this->helper->load('field')->render(
1754 apply_filters('e2pdf_extension_render_shortcodes_pre_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false),
1755 $this,
1756 $field
1757 );
1758 }
1759 return apply_filters(
1760 'e2pdf_extension_render_shortcodes_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false
1761 );
1762 }
1763
1764 /**
1765 * Strip unused shortcodes
1766 * @param string $value - Content
1767 * @return string - Value with removed unused shortcodes
1768 */
1769 public function strip_shortcodes($value) {
1770 $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', '', $value);
1771 return $value;
1772 }
1773
1774 /**
1775 * Convert "shortcodes" inside value string
1776 * @param string $value - Value string
1777 * @param bool $to - Convert From/To
1778 * @return string - Converted value
1779 */
1780 public function convert_shortcodes($value, $to = false, $html = false) {
1781 if ($value) {
1782 if ($to) {
1783 $value = str_replace('&#91;', '[', $value);
1784 if (!$html) {
1785 $value = wp_specialchars_decode($value, ENT_QUOTES);
1786 }
1787 } else {
1788 $value = str_replace('[', '&#91;', $value);
1789 }
1790 }
1791 return $value;
1792 }
1793
1794 public function auto() {
1795 $response = array();
1796 $elements = array();
1797
1798 $line_height = (int) $this->get('line_height');
1799
1800 if ($this->get('item') == 'cart') {
1801
1802 $elements[] = array(
1803 'type' => 'e2pdf-html',
1804 'block' => true,
1805 'properties' => array(
1806 'top' => '20',
1807 'left' => '20',
1808 'right' => '20',
1809 'width' => '50%',
1810 'height' => 'auto',
1811 'value' => '<strong>Billing:</strong>',
1812 ),
1813 );
1814
1815 $elements[] = array(
1816 'type' => 'e2pdf-html',
1817 'block' => true,
1818 'float' => true,
1819 'properties' => array(
1820 'top' => '20',
1821 'left' => '20',
1822 'right' => '20',
1823 'width' => '50%',
1824 'height' => 'auto',
1825 'value' => '<strong>Shipping:</strong>',
1826 ),
1827 );
1828
1829 $elements[] = array(
1830 'type' => 'e2pdf-html',
1831 'block' => true,
1832 'properties' => array(
1833 'top' => '5',
1834 'left' => '20',
1835 'right' => '20',
1836 'width' => '50%',
1837 'height' => $line_height * 7,
1838 'value' => '[e2pdf-wc-customer key="get_formatted_billing_address"]',
1839 ),
1840 );
1841
1842 $elements[] = array(
1843 'type' => 'e2pdf-html',
1844 'block' => true,
1845 'float' => true,
1846 'properties' => array(
1847 'top' => '5',
1848 'left' => '20',
1849 'right' => '20',
1850 'width' => '50%',
1851 'height' => $line_height * 7,
1852 'value' => '[e2pdf-wc-customer key="get_formatted_shipping_address"]',
1853 ),
1854 );
1855
1856 $elements[] = array(
1857 'type' => 'e2pdf-html',
1858 'block' => true,
1859 'properties' => array(
1860 'top' => '10',
1861 'left' => '20',
1862 'right' => '20',
1863 'width' => '50%',
1864 'height' => 'auto',
1865 'value' => '<strong>E-mail:</strong>',
1866 ),
1867 );
1868
1869 $elements[] = array(
1870 'type' => 'e2pdf-html',
1871 'block' => true,
1872 'float' => true,
1873 'properties' => array(
1874 'top' => '10',
1875 'left' => '20',
1876 'right' => '20',
1877 'width' => '50%',
1878 'height' => 'auto',
1879 'value' => '<strong>Phone:</strong>',
1880 ),
1881 );
1882
1883 $elements[] = array(
1884 'type' => 'e2pdf-html',
1885 'block' => true,
1886 'properties' => array(
1887 'top' => '5',
1888 'left' => '20',
1889 'right' => '20',
1890 'width' => '50%',
1891 'height' => 'auto',
1892 'value' => '[e2pdf-wc-customer key="get_billing_email"]',
1893 ),
1894 );
1895
1896 $elements[] = array(
1897 'type' => 'e2pdf-html',
1898 'block' => true,
1899 'float' => true,
1900 'properties' => array(
1901 'top' => '5',
1902 'left' => '20',
1903 'right' => '20',
1904 'width' => '50%',
1905 'height' => 'auto',
1906 'value' => '[e2pdf-wc-customer key="get_billing_phone"]',
1907 ),
1908 );
1909
1910 $elements[] = array(
1911 'type' => 'e2pdf-html',
1912 'block' => true,
1913 'properties' => array(
1914 'wysiwyg_disable' => '1',
1915 'css' => 'td {' . "\r\n"
1916 . 'text-align: center;' . "\r\n"
1917 . 'vertical-align: top;' . "\r\n"
1918 . '}' . "\r\n"
1919 . '.header {' . "\r\n"
1920 . 'background: #eeeeee;' . "\r\n"
1921 . '}' . "\r\n"
1922 . '.item {' . "\r\n"
1923 . 'text-align: left;' . "\r\n"
1924 . 'width: 40%;' . "\r\n"
1925 . '}' . "\r\n"
1926 . '.total-label {' . "\r\n"
1927 . 'text-align: right;' . "\r\n"
1928 . '}' . "\r\n"
1929 . '.total-value {' . "\r\n"
1930 . 'text-align: right;' . "\r\n"
1931 . '}' . "\r\n"
1932 . '.total-order {' . "\r\n"
1933 . 'font-weight: bold;' . "\r\n"
1934 . '}' . "\r\n"
1935 . '.formatted-meta-data {' . "\r\n"
1936 . 'color: #555555;' . "\r\n"
1937 . 'font-size: 8px;' . "\r\n"
1938 . '}' . "\r\n"
1939 . '.hr {' . "\r\n"
1940 . 'background: #eeeeee;' . "\r\n"
1941 . '}' . "\r\n"
1942 . '.attachment-32x32 {' . "\r\n"
1943 . 'margin-top: 5px;' . "\r\n"
1944 . '}' . "\r\n"
1945 . 'ul {' . "\r\n"
1946 . 'padding-left: 10px;' . "\r\n"
1947 . '}' . "\r\n"
1948 . 'li {' . "\r\n"
1949 . 'padding-left: 5px;' . "\r\n"
1950 . '}' . "\r\n",
1951 'top' => '20',
1952 'left' => '20',
1953 'right' => '20',
1954 'width' => '100%',
1955 'height' => 'max',
1956 'value' => '<table cellpadding="5">' . "\r\n"
1957 . '<tr class="header"><td></td><td class="item">Item</td><td align="center">Quantity</td><td align="center">Unit Price</td><td align="center">Subtotal</td></tr>' . "\r\n"
1958 . '[e2pdf-foreach shortcode="e2pdf-wc-cart" key="get_cart"]' . "\r\n"
1959 . '<tr>' . "\r\n"
1960 . '<td>[e2pdf-wc-product key="get_image" size="32x32" index="[e2pdf-foreach-index]" order="true" wc_filter="true"]' . "\r\n"
1961 . '</td>' . "\r\n"
1962 . '<td class="item">' . "\r\n"
1963 . '[e2pdf-wc-product key="get_name" index="[e2pdf-foreach-index]" order="true" wc_filter="true"]' . "\r\n"
1964 . '[e2pdf-foreach-1 shortcode="e2pdf-wc-product" key="get_formatted_meta_data" index="[e2pdf-foreach-index]" order="true"]' . "\r\n"
1965 . '<div class="formatted-meta-data">[e2pdf-wc-product key="get_formatted_meta_data" index="[e2pdf-foreach-index]" path="[e2pdf-foreach-key-1].display_key"]: [e2pdf-wc-product key="get_formatted_meta_data" index="[e2pdf-foreach-index]" path="[e2pdf-foreach-key-1].display_value"]</div>' . "\r\n"
1966 . '[/e2pdf-foreach-1]' . "\r\n"
1967 . '</td>' . "\r\n"
1968 . '<td align="center">[e2pdf-wc-product key="get_quantity" index="[e2pdf-foreach-index]" order="true"]</td>' . "\r\n"
1969 . '<td align="center">[e2pdf-wc-product key="get_product_price" index="[e2pdf-foreach-index]" order="true" wc_filter="true"]</td>' . "\r\n"
1970 . '<td align="center">[e2pdf-wc-product key="get_subtotal" index="[e2pdf-foreach-index]" order="true" wc_filter="true"]</td>' . "\r\n"
1971 . '</tr>' . "\r\n"
1972 . '[/e2pdf-foreach]' . "\r\n"
1973 . '<tr><td colspan="5"><hr class="hr"></td></tr>' . "\r\n"
1974 . '[e2pdf-foreach shortcode="e2pdf-wc-cart" key="get_formatted_cart_totals"]' . "\r\n"
1975 . '<tr><td colspan="3" class="total-label">[e2pdf-wc-cart key="get_formatted_cart_totals" path="[e2pdf-foreach-key].label"]:</td><td colspan="2" class="total-value">[e2pdf-wc-cart key="get_formatted_cart_totals" path="[e2pdf-foreach-key].value"]</td></tr>' . "\r\n"
1976 . '[/e2pdf-foreach]' . "\r\n"
1977 . '</table>' . "\r\n",
1978 ),
1979 );
1980 } elseif ($this->get('item') == 'shop_order' || $this->get('item') == 'shop_subscription') {
1981 $elements[] = array(
1982 'type' => 'e2pdf-html',
1983 'block' => true,
1984 'properties' => array(
1985 'top' => '20',
1986 'left' => '20',
1987 'right' => '20',
1988 'width' => '100%',
1989 'height' => 'auto',
1990 'value' => '<h2>[e2pdf-wc-order key="get_order_number"]</h2>' . "\r\n",
1991 ),
1992 );
1993
1994 $elements[] = array(
1995 'type' => 'e2pdf-html',
1996 'block' => true,
1997 'properties' => array(
1998 'top' => '5',
1999 'left' => '20',
2000 'right' => '20',
2001 'width' => '100%',
2002 'height' => 'auto',
2003 'value' => 'Payment via [e2pdf-wc-order key="get_payment_method_title"]' . "\r\n",
2004 ),
2005 );
2006
2007 $elements[] = array(
2008 'type' => 'e2pdf-html',
2009 'block' => true,
2010 'properties' => array(
2011 'top' => '20',
2012 'left' => '20',
2013 'right' => '20',
2014 'width' => '100%',
2015 'height' => $line_height * 3,
2016 'value' => 'Order ID: [e2pdf-wc-order key="get_id"]<br>'
2017 . 'Date Created: [e2pdf-wc-order key="get_date_created"]<br>' . "\r\n"
2018 . 'Status: [e2pdf-wc-order key="get_status" wc_get_order_status_name="true"]' . "\r\n",
2019 ),
2020 );
2021
2022 $elements[] = array(
2023 'type' => 'e2pdf-html',
2024 'block' => true,
2025 'properties' => array(
2026 'top' => '20',
2027 'left' => '20',
2028 'right' => '20',
2029 'width' => '50%',
2030 'height' => 'auto',
2031 'value' => '<strong>Billing:</strong>',
2032 ),
2033 );
2034
2035 $elements[] = array(
2036 'type' => 'e2pdf-html',
2037 'block' => true,
2038 'float' => true,
2039 'properties' => array(
2040 'top' => '20',
2041 'left' => '20',
2042 'right' => '20',
2043 'width' => '50%',
2044 'height' => 'auto',
2045 'value' => '<strong>Shipping:</strong>',
2046 ),
2047 );
2048
2049 $elements[] = array(
2050 'type' => 'e2pdf-html',
2051 'block' => true,
2052 'properties' => array(
2053 'top' => '5',
2054 'left' => '20',
2055 'right' => '20',
2056 'width' => '50%',
2057 'height' => $line_height * 7,
2058 'value' => '[e2pdf-wc-order key="get_formatted_billing_address"]',
2059 ),
2060 );
2061
2062 $elements[] = array(
2063 'type' => 'e2pdf-html',
2064 'block' => true,
2065 'float' => true,
2066 'properties' => array(
2067 'top' => '5',
2068 'left' => '20',
2069 'right' => '20',
2070 'width' => '50%',
2071 'height' => $line_height * 7,
2072 'value' => '[e2pdf-wc-order key="get_formatted_shipping_address"]',
2073 ),
2074 );
2075
2076 $elements[] = array(
2077 'type' => 'e2pdf-html',
2078 'block' => true,
2079 'properties' => array(
2080 'top' => '10',
2081 'left' => '20',
2082 'right' => '20',
2083 'width' => '50%',
2084 'height' => 'auto',
2085 'value' => '<strong>E-mail:</strong>',
2086 ),
2087 );
2088
2089 $elements[] = array(
2090 'type' => 'e2pdf-html',
2091 'block' => true,
2092 'float' => true,
2093 'properties' => array(
2094 'top' => '10',
2095 'left' => '20',
2096 'right' => '20',
2097 'width' => '50%',
2098 'height' => 'auto',
2099 'value' => '<strong>Phone:</strong>',
2100 ),
2101 );
2102
2103 $elements[] = array(
2104 'type' => 'e2pdf-html',
2105 'block' => true,
2106 'properties' => array(
2107 'top' => '5',
2108 'left' => '20',
2109 'right' => '20',
2110 'width' => '50%',
2111 'height' => 'auto',
2112 'value' => '[e2pdf-wc-order key="get_billing_email"]',
2113 ),
2114 );
2115
2116 $elements[] = array(
2117 'type' => 'e2pdf-html',
2118 'block' => true,
2119 'float' => true,
2120 'properties' => array(
2121 'top' => '5',
2122 'left' => '20',
2123 'right' => '20',
2124 'width' => '50%',
2125 'height' => 'auto',
2126 'value' => '[e2pdf-wc-order key="get_billing_phone"]',
2127 ),
2128 );
2129
2130 $elements[] = array(
2131 'type' => 'e2pdf-html',
2132 'block' => true,
2133 'properties' => array(
2134 'wysiwyg_disable' => '1',
2135 'css' => 'td {' . "\r\n"
2136 . 'text-align: center;' . "\r\n"
2137 . 'vertical-align: top;' . "\r\n"
2138 . '}' . "\r\n"
2139 . '.header {' . "\r\n"
2140 . 'background: #eeeeee;' . "\r\n"
2141 . '}' . "\r\n"
2142 . '.item {' . "\r\n"
2143 . 'text-align: left;' . "\r\n"
2144 . 'width: 40%;' . "\r\n"
2145 . '}' . "\r\n"
2146 . '.total-label {' . "\r\n"
2147 . 'text-align: right;' . "\r\n"
2148 . '}' . "\r\n"
2149 . '.total-value {' . "\r\n"
2150 . 'text-align: right;' . "\r\n"
2151 . '}' . "\r\n"
2152 . '.total-order {' . "\r\n"
2153 . 'font-weight: bold;' . "\r\n"
2154 . '}' . "\r\n"
2155 . '.formatted-meta-data {' . "\r\n"
2156 . 'color: #555555;' . "\r\n"
2157 . 'font-size: 8px;' . "\r\n"
2158 . '}' . "\r\n"
2159 . '.hr {' . "\r\n"
2160 . 'background-color: #eeeeee;' . "\r\n"
2161 . '}' . "\r\n"
2162 . '.attachment-32x32 {' . "\r\n"
2163 . 'margin-top: 5px;' . "\r\n"
2164 . '}' . "\r\n"
2165 . 'ul {' . "\r\n"
2166 . 'padding-left: 10px;' . "\r\n"
2167 . '}' . "\r\n"
2168 . 'li {' . "\r\n"
2169 . 'padding-left: 5px;' . "\r\n"
2170 . '}' . "\r\n",
2171 'top' => '20',
2172 'left' => '20',
2173 'right' => '20',
2174 'width' => '100%',
2175 'height' => 'max',
2176 'value' => '<table cellpadding="5">' . "\r\n"
2177 . '<tr class="header"><td class="item">Item</td><td align="center">Quantity</td><td align="center">Unit Price</td><td align="center">Subtotal</td><td align="center">Total</td></tr>' . "\r\n"
2178 . '[e2pdf-foreach shortcode="e2pdf-wc-order" key="get_items"]' . "\r\n"
2179 . '<tr>' . "\r\n"
2180 . '<td class="item">' . "\r\n"
2181 . '[e2pdf-wc-product key="get_name" index="[e2pdf-foreach-index]" order="true"]' . "\r\n"
2182 . '[e2pdf-foreach-1 shortcode="e2pdf-wc-product" key="get_formatted_meta_data" index="[e2pdf-foreach-index]"]' . "\r\n"
2183 . '<div class="formatted-meta-data">[e2pdf-wc-product key="get_formatted_meta_data" index="[e2pdf-foreach-index]" path="[e2pdf-foreach-key-1].display_key"]: [e2pdf-wc-product key="get_formatted_meta_data" index="[e2pdf-foreach-index]" path="[e2pdf-foreach-key-1].display_value"]</div>' . "\r\n"
2184 . '[/e2pdf-foreach-1]' . "\r\n"
2185 . '</td>' . "\r\n"
2186 . '<td align="center">[e2pdf-wc-product key="get_quantity" index="[e2pdf-foreach-index]" order="true"]</td>' . "\r\n"
2187 . '<td align="center">[e2pdf-wc-product key="get_item_subtotal" index="[e2pdf-foreach-index]" order="true" wc_price="true"]</td>' . "\r\n"
2188 . '<td align="center">[e2pdf-wc-product key="get_subtotal" index="[e2pdf-foreach-index]" order="true" wc_price="true"]</td>' . "\r\n"
2189 . '<td align="center">[e2pdf-wc-product key="get_total" index="[e2pdf-foreach-index]" order="true" wc_price="true"]</td>' . "\r\n"
2190 . '</tr>' . "\r\n"
2191 . '[/e2pdf-foreach]' . "\r\n"
2192 . '<tr><td colspan="5"><hr class="hr"></td></tr>' . "\r\n"
2193 . '[e2pdf-foreach shortcode="e2pdf-wc-order" key="get_order_item_totals"]' . "\r\n"
2194 . '<tr>' . "\r\n"
2195 . '<td colspan="3" class="total-label">[e2pdf-wc-order key="get_order_item_totals" path="[e2pdf-foreach-key].label"]</td>' . "\r\n"
2196 . '<td colspan="2" class="total-value">[e2pdf-wc-order key="get_order_item_totals" path="[e2pdf-foreach-key].value"]</td>' . "\r\n"
2197 . '</tr>' . "\r\n"
2198 . '[/e2pdf-foreach]' . "\r\n"
2199 . '</table>' . "\r\n",
2200 ),
2201 );
2202 } elseif ($this->get('item') == 'product' || $this->get('item') == 'product_variation') {
2203
2204 $elements[] = array(
2205 'type' => 'e2pdf-html',
2206 'block' => true,
2207 'float' => true,
2208 'properties' => array(
2209 'top' => '20',
2210 'left' => '20',
2211 'right' => '20',
2212 'width' => '100%',
2213 'height' => 'auto',
2214 'value' => '<hr>',
2215 ),
2216 );
2217
2218 $elements[] = array(
2219 'type' => 'e2pdf-image',
2220 'properties' => array(
2221 'top' => '20',
2222 'width' => '110',
2223 'height' => '110',
2224 'value' => '[e2pdf-wc-product key="get_image"]',
2225 'dimension' => '1',
2226 'vertical' => 'top',
2227 'horizontal' => 'center',
2228 ),
2229 );
2230
2231 if ($this->get('item') == 'product_variation') {
2232
2233 $elements[] = array(
2234 'type' => 'e2pdf-html',
2235 'float' => true,
2236 'properties' => array(
2237 'left' => '20',
2238 'right' => '110',
2239 'height' => '110',
2240 'width' => '100%',
2241 'value' => '<h2>[e2pdf-wc-product key="get_name"]</h2><br>' . "\r\n"
2242 . '<div>Price: [e2pdf-wc-product key="get_price" wc_price="true"]</div>' . "\r\n",
2243 ),
2244 );
2245
2246 $elements[] = array(
2247 'type' => 'e2pdf-html',
2248 'block' => true,
2249 'float' => true,
2250 'properties' => array(
2251 'top' => '20',
2252 'left' => '20',
2253 'right' => '20',
2254 'width' => '100%',
2255 'height' => 'max',
2256 'wysiwyg_disable' => '1',
2257 'value' =>
2258 '<table cellpadding="5">' . "\r\n"
2259 . '<tr><td colspan="2"><b>Additional Information:</b></td></tr>' . "\r\n"
2260 . '[e2pdf-foreach shortcode="e2pdf-wc-product" key="get_attributes" wc_filter="true"]' . "\r\n"
2261 . '<tr>' . "\r\n"
2262 . '<td>[e2pdf-wc-product key="get_attributes" path="[e2pdf-foreach-key].label" wc_filter="true"]:</td>' . "\r\n"
2263 . '<td>[e2pdf-wc-product key="get_attributes" path="[e2pdf-foreach-key].value" wc_filter="true"]</td>' . "\r\n"
2264 . '</tr>' . "\r\n"
2265 . '[/e2pdf-foreach]' . "\r\n"
2266 . '</table>' . "\r\n"
2267 . '<table cellpadding="5">' . "\r\n"
2268 . '<tr><td><b>Description</b></td></tr>' . "\r\n"
2269 . '<tr><td>[e2pdf-wc-product key="get_description" wc_format_content="true"]</td></tr>' . "\r\n"
2270 . '</table>' . "\r\n",
2271 ),
2272 );
2273 } else {
2274
2275 $elements[] = array(
2276 'type' => 'e2pdf-html',
2277 'float' => true,
2278 'properties' => array(
2279 'left' => '20',
2280 'right' => '110',
2281 'height' => '110',
2282 'width' => '100%',
2283 'value' => '<h2>[e2pdf-wc-product key="get_name"]</h2><br>' . "\r\n"
2284 . '<div>Price: [e2pdf-wc-product key="get_price" wc_price="true"]</div>' . "\r\n",
2285 ),
2286 );
2287
2288 $elements[] = array(
2289 'type' => 'e2pdf-html',
2290 'block' => true,
2291 'float' => true,
2292 'properties' => array(
2293 'top' => '20',
2294 'left' => '20',
2295 'right' => '20',
2296 'width' => '100%',
2297 'height' => 'max',
2298 'wysiwyg_disable' => '1',
2299 'value' =>
2300 '<table cellpadding="5">' . "\r\n"
2301 . '<tr><td colspan="2"><b>Additional Information:</b></td></tr>' . "\r\n"
2302 . '[e2pdf-foreach shortcode="e2pdf-wc-product" key="get_attributes" wc_filter="true"]' . "\r\n"
2303 . '<tr>' . "\r\n"
2304 . '<td>[e2pdf-wc-product key="get_attributes" path="[e2pdf-foreach-key].label" wc_filter="true"]:</td>' . "\r\n"
2305 . '<td>[e2pdf-wc-product key="get_attributes" path="[e2pdf-foreach-key].value" wc_filter="true"]</td>' . "\r\n"
2306 . '</tr>' . "\r\n"
2307 . '[/e2pdf-foreach]' . "\r\n"
2308 . '</table>' . "\r\n"
2309 . '<table cellpadding="5">' . "\r\n"
2310 . '<tr><td><b>Short Description</b></td></tr>' . "\r\n"
2311 . '<tr><td>[e2pdf-wc-product key="get_short_description" wc_format_content="true"]</td></tr>' . "\r\n"
2312 . '</table>' . "\r\n",
2313 ),
2314 );
2315 }
2316 }
2317
2318 $response['page'] = array(
2319 'bottom' => '20',
2320 'top' => '20',
2321 'left' => '20',
2322 'right' => '20',
2323 );
2324
2325 $response['elements'] = $elements;
2326 return $response;
2327 }
2328
2329 public function filter_content_custom($content) {
2330 $content = $this->filter_content($content);
2331 return $content;
2332 }
2333
2334 public function filter_the_content($content, $post_id = false) {
2335 $content = $this->filter_content($content, $post_id);
2336 return $content;
2337 }
2338
2339 /**
2340 * Search and update shortcodes for this extension inside content
2341 * Auto set of dataset id
2342 * @param string $content - Content
2343 * @param string $post_id - Custom Post ID
2344 * @return string - Content with updated shortcodes
2345 */
2346 public function filter_content($content, $post_id = false, $download = false, $wp_reset_postdata = true) {
2347 global $post;
2348 if (!is_string($content) || false === strpos($content, '[')) {
2349 return $content;
2350 }
2351 $shortcode_tags = array(
2352 'e2pdf-download',
2353 'e2pdf-save',
2354 'e2pdf-view',
2355 'e2pdf-adobesign',
2356 'e2pdf-zapier',
2357 );
2358 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
2359 $tagnames = array_intersect($shortcode_tags, $matches[1]);
2360 if (!empty($tagnames)) {
2361 preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
2362 foreach ($shortcodes[0] as $key => $shortcode_value) {
2363 $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
2364 $atts = shortcode_parse_atts($shortcode[3]);
2365 if (isset($atts['wp_reset_postdata'])) {
2366 if ($atts['wp_reset_postdata'] == 'true') {
2367 $wp_reset_postdata = true;
2368 } else {
2369 $wp_reset_postdata = false;
2370 }
2371 }
2372 if ($wp_reset_postdata) {
2373 wp_reset_postdata();
2374 }
2375 if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
2376 } else {
2377 if (isset($atts['id'])) {
2378 $template = new Model_E2pdf_Template();
2379 $template->load($atts['id']);
2380 if ($template->get('extension') === 'wordpress' || $template->get('extension') === 'jetformbuilder') { // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
2381 if (!$download) {
2382 continue;
2383 }
2384 } elseif ($template->get('extension') === 'gravity') {
2385 if (!isset($atts['dataset'])) {
2386 if (function_exists('wc_get_order') && isset($_GET['order'])) {
2387 $order_id = wc_get_order_id_by_order_key(wc_clean(wp_unslash($_GET['order'])));
2388 if ($order_id) {
2389 $item_id = isset($_GET['item_id']) && $_GET['item_id'] ? wc_clean(wp_unslash($_GET['item_id'])) : false;
2390 if ($item_id) {
2391 $order = wc_get_order($order_id);
2392 if ($order && method_exists($order, 'get_items')) {
2393 $order_items = $order->get_items();
2394 if (isset($order_items[$item_id])) {
2395 $linked_entry_id = false;
2396 if ($linked_data = wc_get_order_item_meta($item_id, '_gravity_forms_history', true)) {
2397 if (!empty($linked_data['_gravity_form_linked_entry_id'])) {
2398 $linked_entry_id = $linked_data['_gravity_form_linked_entry_id'];
2399 }
2400 } elseif ($linked_data = wc_get_order_item_meta($item_id, 'gspc_gf_entry_ids', true)) {
2401 if (!empty($linked_data) && isset($linked_data[0])) {
2402 $linked_entry_id = $linked_data[0];
2403 }
2404 }
2405 if ($linked_entry_id) {
2406 $atts['dataset'] = $linked_entry_id;
2407 $shortcode[3] .= ' dataset="' . $linked_entry_id . '"';
2408 }
2409 }
2410 }
2411 }
2412 }
2413 }
2414 }
2415 } elseif ($template->get('extension') === 'formidable') {
2416 if (!isset($atts['dataset'])) {
2417 if (function_exists('wc_get_order') && isset($_GET['order'])) {
2418 $order_id = wc_get_order_id_by_order_key(wc_clean(wp_unslash($_GET['order'])));
2419 if ($order_id) {
2420 $item_id = isset($_GET['item_id']) && $_GET['item_id'] ? wc_clean(wp_unslash($_GET['item_id'])) : false;
2421 if ($item_id) {
2422 $order = wc_get_order($order_id);
2423 if ($order && method_exists($order, 'get_items')) {
2424 $order_items = $order->get_items();
2425 if (isset($order_items[$item_id])) {
2426 $_formidable_form_data = wc_get_order_item_meta($item_id, '_formidable_form_data', true);
2427 if ($_formidable_form_data) {
2428 $atts['dataset'] = $_formidable_form_data;
2429 $shortcode[3] .= ' dataset="' . $_formidable_form_data . '"';
2430 }
2431 }
2432 }
2433 }
2434 }
2435 }
2436 }
2437 } elseif ($template->get('extension') === 'woocommerce') {
2438 if (!isset($atts['dataset']) && ($template->get('item') == 'shop_order' || $template->get('item') == 'shop_subscription') && function_exists('wc_get_order') && isset($_GET['order'])) {
2439 $order_id = wc_get_order_id_by_order_key(wc_clean(wp_unslash($_GET['order'])));
2440
2441 if (function_exists('wcs_get_subscription') && $template->get('item') == 'shop_order' && get_post_type($order_id) == 'shop_subscription') {
2442 $subscription = wcs_get_subscription($order_id);
2443 if ($subscription) {
2444 $subscription_order = $subscription->get_parent();
2445 if ($subscription_order) {
2446 $order_id = $subscription_order->get_id();
2447 }
2448 }
2449 }
2450
2451 if ($order_id) {
2452 $atts['dataset'] = $order_id;
2453 $shortcode[3] .= ' dataset="' . $order_id . '"';
2454 }
2455 }
2456 if (!isset($atts['dataset']) && ($post_id || isset($post->ID))) {
2457 $dataset_id = $post_id ? $post_id : $post->ID;
2458 $atts['dataset'] = $dataset_id;
2459 $shortcode[3] .= ' dataset="' . $dataset_id . '"';
2460 }
2461 if (($template->get('item') == 'product' || $template->get('item') == 'product_variation') && function_exists('wc_get_order') && isset($_GET['order'])) {
2462 $order_id = wc_get_order_id_by_order_key(wc_clean(wp_unslash($_GET['order'])));
2463 if ($order_id) {
2464 $atts['wc_order_id'] = $order_id;
2465 $shortcode[3] .= ' wc_order_id="' . $order_id . '"';
2466
2467 $item_id = isset($_GET['item_id']) && $_GET['item_id'] ? wc_clean(wp_unslash($_GET['item_id'])) : false;
2468 if ($item_id) {
2469 $order = wc_get_order($order_id);
2470 if ($order && method_exists($order, 'get_items')) {
2471 $order_items = $order->get_items();
2472 if (isset($order_items[$item_id])) {
2473 $atts['wc_product_item_id'] = $item_id;
2474 $shortcode[3] .= ' wc_product_item_id="' . $item_id . '"';
2475 }
2476 }
2477 }
2478 }
2479 }
2480 }
2481 }
2482 if (!isset($atts['apply'])) {
2483 $shortcode[3] .= ' apply="true"';
2484 }
2485 if (!isset($atts['filter'])) {
2486 $shortcode[3] .= ' filter="true"';
2487 }
2488 if ($download) {
2489 $site_url = str_replace(array('http:', 'https:'), array('', ''), $this->helper->load('translator')->translate_url($this->helper->get_frontend_site_url()));
2490 $shortcode[3] .= ' output="url" site_url="' . $site_url . '" esc_url_raw="true" wc_product_download="true"';
2491 }
2492 $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content);
2493 }
2494 }
2495 }
2496 return $content;
2497 }
2498
2499 public function filter_woocommerce_product_downloads_approved_directory_validation_for_shortcodes($enabled) {
2500 if (get_option('wc_downloads_approved_directories_mode') === 'enabled') {
2501 return false;
2502 }
2503 return $enabled;
2504 }
2505
2506 /**
2507 * Verify if item and dataset exists
2508 * @return bool - item and dataset exists
2509 */
2510 public function verify() {
2511 if (
2512 $this->get('item') && $this->get('cached_post') &&
2513 (
2514 ($this->get('item') == get_post_type($this->get('cached_post'))) ||
2515 ($this->get('item') == 'cart' && $this->get('dataset') == wc_get_page_id('cart')) ||
2516 ($this->get('item') == 'shop_order' && get_post_type($this->get('cached_post')) == 'shop_order_placehold')
2517 )
2518 ) {
2519 return true;
2520 }
2521 return false;
2522 }
2523
2524 /**
2525 * Init Visual Mapper data
2526 * @return bool|string - HTML data source for Visual Mapper
2527 */
2528 public function visual_mapper() {
2529
2530 $vc = '';
2531
2532 if ($this->get('item') == 'cart') {
2533 $vc .= '<h3 class="e2pdf-plr5">Cart</h3>';
2534 $vc .= '<div class="e2pdf-grid">';
2535 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cart', 'e2pdf-wc-cart key="cart"') . '</div>';
2536 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cart Products', 'e2pdf-wc-cart key="get_cart"') . '</div>';
2537 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Applied Coupons', 'e2pdf-wc-cart key="get_applied_coupons"') . '</div>';
2538 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cart Total', 'e2pdf-wc-cart key="get_cart_total"') . '</div>';
2539 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cart Subtotal', 'e2pdf-wc-cart key="get_cart_subtotal"') . '</div>';
2540 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cart Tax', 'e2pdf-wc-cart key="get_cart_tax"') . '</div>';
2541 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cart Hash', 'e2pdf-wc-cart key="get_cart_hash"') . '</div>';
2542 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cart Contents Total', 'e2pdf-wc-cart key="get_cart_contents_total"') . '</div>';
2543 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cart Contents Tax', 'e2pdf-wc-cart key="get_cart_contents_tax"') . '</div>';
2544 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cart Contents Taxes', 'e2pdf-wc-cart key="get_cart_contents_taxes"') . '</div>';
2545 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cart Contents Count', 'e2pdf-wc-cart key="get_cart_contents_count"') . '</div>';
2546 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cart Contents Weight', 'e2pdf-wc-cart key="get_cart_contents_weight"') . '</div>';
2547 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cart Item Quantities', 'e2pdf-wc-cart key="get_cart_item_quantities"') . '</div>';
2548 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cart Item Tax Classes', 'e2pdf-wc-cart key="get_cart_item_tax_classes"') . '</div>';
2549 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cart Item Tax Classes For Shipping', 'e2pdf-wc-cart key="get_cart_item_tax_classes_for_shipping"') . '</div>';
2550 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cart Shipping Total', 'e2pdf-wc-cart key="get_cart_shipping_total"') . '</div>';
2551 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Coupon Discount Totals', 'e2pdf-wc-cart key="get_coupon_discount_totals"') . '</div>';
2552 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Coupon Discount Tax Totals', 'e2pdf-wc-cart key="get_coupon_discount_tax_totals"') . '</div>';
2553 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Totals', 'e2pdf-wc-cart key="get_totals"') . '</div>';
2554 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Total', 'e2pdf-wc-cart key="get_total"') . '</div>';
2555 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Total Tax', 'e2pdf-wc-cart key="get_total_tax"') . '</div>';
2556 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Total Ex Tax', 'e2pdf-wc-cart key="get_total_ex_tax"') . '</div>';
2557 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Total Discount', 'e2pdf-wc-cart key="get_total_discount"') . '</div>';
2558 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Subtotal', 'e2pdf-wc-cart key="get_subtotal"') . '</div>';
2559 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Subtotal Tax', 'e2pdf-wc-cart key="get_subtotal_tax"') . '</div>';
2560 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Discount Total', 'e2pdf-wc-cart key="get_discount_total"') . '</div>';
2561 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Discount Tax', 'e2pdf-wc-cart key="get_discount_tax"') . '</div>';
2562 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Total', 'e2pdf-wc-cart key="get_shipping_total"') . '</div>';
2563 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Tax', 'e2pdf-wc-cart key="get_shipping_tax"') . '</div>';
2564 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Taxes', 'e2pdf-wc-cart key="get_shipping_taxes"') . '</div>';
2565 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Fees', 'e2pdf-wc-cart key="get_fees"') . '</div>';
2566 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Fee Total', 'e2pdf-wc-cart key="get_fee_total"') . '</div>';
2567 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Fee Tax', 'e2pdf-wc-cart key="get_fee_tax"') . '</div>';
2568 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Fee Taxes', 'e2pdf-wc-cart key="get_fee_taxes"') . '</div>';
2569 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Displayed Subtotal', 'e2pdf-wc-cart key="get_displayed_subtotal"') . '</div>';
2570 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Tax Price Display Mode', 'e2pdf-wc-cart key="get_tax_price_display_mode"') . '</div>';
2571 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Taxes', 'e2pdf-wc-cart key="get_taxes"') . '</div>';
2572 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Taxes Total', 'e2pdf-wc-cart key="get_taxes_total"') . '</div>';
2573 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Taxes Total', 'e2pdf-wc-cart key="get_shipping_method_title"') . '</div>';
2574 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Taxes Total', 'e2pdf-wc-cart key="get_payment_method_title"') . '</div>';
2575 $vc .= '</div>';
2576
2577 $vc .= '<h3 class="e2pdf-plr5">Cart Common</h3>';
2578 $vc .= '<div class="e2pdf-grid">';
2579 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('ID', 'e2pdf-wc-cart key="id"') . '</div>';
2580 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Author', 'e2pdf-wc-cart key="post_author"') . '</div>';
2581 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Author ID', 'e2pdf-wc-cart key="post_author_id"') . '</div>';
2582 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date', 'e2pdf-wc-cart key="post_date"') . '</div>';
2583 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date (GMT)', 'e2pdf-wc-cart key="post_date_gmt"') . '</div>';
2584 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Content', 'e2pdf-wc-cart key="post_content"') . '</div>';
2585 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Title', 'e2pdf-wc-cart key="post_title"') . '</div>';
2586 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Excerpt', 'e2pdf-wc-cart key="post_excerpt"') . '</div>';
2587 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Status', 'e2pdf-wc-cart key="post_status"') . '</div>';
2588 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Comment Status', 'e2pdf-wc-cart key="comment_status"') . '</div>';
2589 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Ping Status', 'e2pdf-wc-cart key="ping_status"') . '</div>';
2590 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Password', 'e2pdf-wc-cart key="post_password"') . '</div>';
2591 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Name', 'e2pdf-wc-cart key="post_name"') . '</div>';
2592 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('To Ping', 'e2pdf-wc-cart key="to_ping"') . '</div>';
2593 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Ping', 'e2pdf-wc-cart key="pinged"') . '</div>';
2594 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Modified Date', 'e2pdf-wc-cart key="post_modified"') . '</div>';
2595 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Modified Date (GMT)', 'e2pdf-wc-cart key="post_modified_gmt"') . '</div>';
2596 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Filtered Content', 'e2pdf-wc-cart key="post_content_filtered"') . '</div>';
2597 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Parent ID', 'e2pdf-wc-cart key="post_parent"') . '</div>';
2598 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('GUID', 'e2pdf-wc-cart key="guid"') . '</div>';
2599 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Menu Order', 'e2pdf-wc-cart key="menu_order"') . '</div>';
2600 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Type', 'e2pdf-wc-cart key="post_type"') . '</div>';
2601 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Mime Type', 'e2pdf-wc-cart key="post_mime_type"') . '</div>';
2602 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Comments Count', 'e2pdf-wc-cart key="comment_count"') . '</div>';
2603 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Filter', 'e2pdf-wc-cart key="filter"') . '</div>';
2604 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Post Thumbnail', 'e2pdf-wc-cart key="get_the_post_thumbnail"') . '</div>';
2605 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Post Thumbnail URL', 'e2pdf-wc-cart key="get_the_post_thumbnail_url"') . '</div>';
2606 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Permalink', 'e2pdf-wc-cart key="permalink"') . '</div>';
2607 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Post Permalink', 'e2pdf-wc-cart key="get_post_permalink"') . '</div>';
2608 $vc .= '</div>';
2609
2610 $vc .= '<h3 class="e2pdf-plr5">Cart Special Shortcodes</h3>';
2611 $vc .= '<div class="e2pdf-grid">';
2612 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cart Products', 'e2pdf-foreach shortcode="e2pdf-wc-cart" key="get_cart"][e2pdf-wc-product key="get_name" index="[e2pdf-foreach-index]" order="true" wc_filter="true"]' . "\r\n" . '[/e2pdf-foreach') . '</div>';
2613 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cart Totals', 'e2pdf-foreach shortcode="e2pdf-wc-cart" key="get_formatted_cart_totals"][e2pdf-wc-cart key="get_formatted_cart_totals" path="[e2pdf-foreach-key].label"]:[e2pdf-wc-cart key="get_formatted_cart_totals" path="[e2pdf-foreach-key].value"]' . "\r\n" . '[/e2pdf-foreach') . '</div>';
2614 $vc .= '</div>';
2615
2616 if (function_exists('wc_get_page_id')) {
2617 $meta_keys = $this->get_post_meta_keys(false, wc_get_page_id('cart'));
2618 if (!empty($meta_keys)) {
2619 $vc .= '<h3 class="e2pdf-plr5">Cart Meta Keys</h3>';
2620 $vc .= '<div class="e2pdf-grid">';
2621 $i = 0;
2622 foreach ($meta_keys as $meta_key) {
2623 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($meta_key, 'e2pdf-wc-cart key="' . $meta_key . '" meta="true"') . '</div>';
2624 $i++;
2625 }
2626 $vc .= '</div>';
2627 }
2628 }
2629 $vc .= $this->get_vm_product_order();
2630 $vc .= $this->get_vm_product();
2631 $vc .= '<h3 class="e2pdf-plr5">Customer</h3>';
2632 $vc .= '<div class="e2pdf-grid">';
2633 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Taxable Address', 'e2pdf-wc-customer key="get_taxable_address"') . '</div>';
2634 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Is Vat Exempt', 'e2pdf-wc-customer key="is_vat_exempt"') . '</div>';
2635 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Is Vat Exempt', 'e2pdf-wc-customer key="get_is_vat_exempt"') . '</div>';
2636 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Has Calculated Shipping', 'e2pdf-wc-customer key="has_calculated_shipping"') . '</div>';
2637 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Calculated Shipping', 'e2pdf-wc-customer key="get_calculated_shipping"') . '</div>';
2638 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Avatar Url', 'e2pdf-wc-customer key="get_avatar_url"') . '</div>';
2639 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Username', 'e2pdf-wc-customer key="get_username"') . '</div>';
2640 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('E-mail', 'e2pdf-wc-customer key="get_email"') . '</div>';
2641 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('First Name', 'e2pdf-wc-customer key="get_first_name"') . '</div>';
2642 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Last Name', 'e2pdf-wc-customer key="get_last_name"') . '</div>';
2643 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Display Name', 'e2pdf-wc-customer key="get_display_name"') . '</div>';
2644 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Role', 'e2pdf-wc-customer key="get_role"') . '</div>';
2645 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date Created', 'e2pdf-wc-customer key="get_date_created"') . '</div>';
2646 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date Modified', 'e2pdf-wc-customer key="get_date_modified"') . '</div>';
2647 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing', 'e2pdf-wc-customer key="get_billing"') . '</div>';
2648 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing First Name', 'e2pdf-wc-customer key="get_billing_first_name"') . '</div>';
2649 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing Last Name', 'e2pdf-wc-customer key="get_billing_last_name"') . '</div>';
2650 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing Company', 'e2pdf-wc-customer key="get_billing_company"') . '</div>';
2651 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing Address', 'e2pdf-wc-customer key="get_billing_address"') . '</div>';
2652 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing Address 1', 'e2pdf-wc-customer key="get_billing_address_1"') . '</div>';
2653 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing Address 2', 'e2pdf-wc-customer key="get_billing_address_2"') . '</div>';
2654 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing City', 'e2pdf-wc-customer key="get_billing_city"') . '</div>';
2655 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing State', 'e2pdf-wc-customer key="get_billing_state"') . '</div>';
2656 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing Postcode', 'e2pdf-wc-customer key="get_billing_postcode"') . '</div>';
2657 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing E-mail', 'e2pdf-wc-customer key="get_billing_email"') . '</div>';
2658 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing Phone', 'e2pdf-wc-customer key="get_billing_phone"') . '</div>';
2659 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping', 'e2pdf-wc-customer key="get_shipping"') . '</div>';
2660 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping First Name', 'e2pdf-wc-customer key="get_shipping_first_name"') . '</div>';
2661 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Last Name', 'e2pdf-wc-customer key="get_shipping_last_name"') . '</div>';
2662 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Company', 'e2pdf-wc-customer key="get_shipping_company"') . '</div>';
2663 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Address', 'e2pdf-wc-customer key="get_shipping_address"') . '</div>';
2664 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Address 1', 'e2pdf-wc-customer key="get_shipping_address_1"') . '</div>';
2665 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Address 2', 'e2pdf-wc-customer key="get_shipping_address_2"') . '</div>';
2666 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping City', 'e2pdf-wc-customer key="get_shipping_city"') . '</div>';
2667 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping State', 'e2pdf-wc-customer key="get_shipping_state"') . '</div>';
2668 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Postcode', 'e2pdf-wc-customer key="get_shipping_postcode"') . '</div>';
2669 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Country', 'e2pdf-wc-customer key="get_shipping_country"') . '</div>';
2670 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Is Paying Customer', 'e2pdf-wc-customer key="get_is_paying_customer"') . '</div>';
2671 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Formatted Shipping Address', 'e2pdf-wc-customer key="get_formatted_shipping_address"') . '</div>';
2672 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Formatted Billing Address', 'e2pdf-wc-customer key="get_formatted_billing_address"') . '</div>';
2673 $vc .= '</div>';
2674 }
2675
2676 if ($this->get('item') == 'shop_order' || $this->get('item') == 'shop_subscription') {
2677 $vc .= $this->get_vm_order($this->get('item'));
2678 $vc .= '<h3 class="e2pdf-plr5">Order Common</h3>';
2679 $vc .= '<div class="e2pdf-grid">';
2680 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('ID', 'e2pdf-wc-order key="id"') . '</div>';
2681 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Author', 'e2pdf-wc-order key="post_author"') . '</div>';
2682 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Author ID', 'e2pdf-wc-order key="post_author_id"') . '</div>';
2683 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date', 'e2pdf-wc-order key="post_date"') . '</div>';
2684 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date (GMT)', 'e2pdf-wc-order key="post_date_gmt"') . '</div>';
2685 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Content', 'e2pdf-wc-order key="post_content"') . '</div>';
2686 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Title', 'e2pdf-wc-order key="post_title"') . '</div>';
2687 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Excerpt', 'e2pdf-wc-order key="post_excerpt"') . '</div>';
2688 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Status', 'e2pdf-wc-order key="post_status"') . '</div>';
2689 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Comment Status', 'e2pdf-wc-order key="comment_status"') . '</div>';
2690 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Ping Status', 'e2pdf-wc-order key="ping_status"') . '</div>';
2691 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Password', 'e2pdf-wc-order key="post_password"') . '</div>';
2692 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Name', 'e2pdf-wc-order key="post_name"') . '</div>';
2693 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('To Ping', 'e2pdf-wc-order key="to_ping"') . '</div>';
2694 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Ping', 'e2pdf-wc-order key="pinged"') . '</div>';
2695 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Modified Date', 'e2pdf-wc-order key="post_modified"') . '</div>';
2696 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Modified Date (GMT)', 'e2pdf-wc-order key="post_modified_gmt"') . '</div>';
2697 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Filtered Content', 'e2pdf-wc-order key="post_content_filtered"') . '</div>';
2698 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Parent ID', 'e2pdf-wc-order key="post_parent"') . '</div>';
2699 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('GUID', 'e2pdf-wc-order key="guid"') . '</div>';
2700 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Menu Order', 'e2pdf-wc-order key="menu_order"') . '</div>';
2701 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Type', 'e2pdf-wc-order key="post_type"') . '</div>';
2702 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Mime Type', 'e2pdf-wc-order key="post_mime_type"') . '</div>';
2703 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Comments Count', 'e2pdf-wc-order key="comment_count"') . '</div>';
2704 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Filter', 'e2pdf-wc-order key="filter"') . '</div>';
2705 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Post Thumbnail', 'e2pdf-wc-order key="get_the_post_thumbnail"') . '</div>';
2706 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Post Thumbnail URL', 'e2pdf-wc-order key="get_the_post_thumbnail_url"') . '</div>';
2707 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Permalink', 'e2pdf-wc-order key="permalink"') . '</div>';
2708 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Post Permalink', 'e2pdf-wc-order key="get_post_permalink"') . '</div>';
2709 $vc .= '</div>';
2710 $vc .= $this->get_vm_product_order();
2711 $vc .= $this->get_vm_product_order_item_meta();
2712 $vc .= $this->get_vm_product();
2713 }
2714
2715 if ($this->get('item') == 'product' || $this->get('item') == 'product_variation') {
2716 $vc .= $this->get_vm_product();
2717 $vc .= $this->get_vm_product_order();
2718 $vc .= $this->get_vm_product_order_item_meta();
2719 $vc .= $this->get_vm_order();
2720 }
2721
2722 if (class_exists('ACF') && function_exists('acf_get_field_groups')) {
2723 $user_groups = acf_get_field_groups(
2724 array(
2725 'user_id' => 'new',
2726 'user_form' => 'all',
2727 )
2728 );
2729 if (!empty($user_groups)) {
2730 $user_groups = array_column($user_groups, 'key');
2731 }
2732 if ($this->get('item') == 'product' || $this->get('item') == 'product_variation') {
2733 $groups = acf_get_field_groups(array('post_type' => 'product'));
2734 } elseif ($this->get('item') == 'shop_order') {
2735 $groups = acf_get_field_groups(array('post_type' => 'shop_order'));
2736 } elseif ($this->get('item') == 'shop_subscription') {
2737 $groups = acf_get_field_groups(array('post_type' => 'shop_subscription'));
2738 } else {
2739 $groups = array();
2740 }
2741 if (!empty($groups)) {
2742 $vc .= "<h3 class='e2pdf-plr5'>ACF</h3>";
2743 foreach ($groups as $group_key => $group) {
2744 $post_id = '';
2745 if (!empty($user_groups)) {
2746 if (in_array($group['key'], $user_groups, false)) {
2747 if ($this->get('item') == '-3') {
2748 $post_id = ' post_id="user_[e2pdf-dataset]"';
2749 } else {
2750 $post_id = ' post_id="user_[e2pdf-userid]"';
2751 }
2752 }
2753 }
2754
2755 $vc .= '<h3 class="e2pdf-plr5">' . $group['title'] . '</h3>';
2756 $vc .= "<div class='e2pdf-grid'>";
2757 foreach (acf_get_fields($group['key']) as $field_key => $field) {
2758 $vc = $this->get_acf_field($vc, $field, $post_id);
2759 }
2760 $vc .= '</div>';
2761 }
2762 }
2763 }
2764
2765 $vc .= $this->get_vm_user();
2766
2767 return $vc;
2768 }
2769
2770 public function get_acf_field($vc, $field, $post_id) {
2771 if ($field['type'] == 'repeater' && !empty($field['sub_fields'])) {
2772 $sub_fields = array();
2773 foreach ($field['sub_fields'] as $sub_field_key => $sub_field) {
2774 $sub_fields[] = '[acf field="' . $sub_field['name'] . '"' . $post_id . ']';
2775 $sub_field['label'] = $field['label'] . ' ' . $sub_field['label'];
2776 $sub_field['name'] = $field['name'] . '_0_' . $sub_field['name'];
2777 $vc = $this->get_acf_field($vc, $sub_field, $post_id);
2778 }
2779 if (!empty($sub_fields)) {
2780 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($field['label'] . ' Iteration', 'e2pdf-acf-repeater field="' . $field['name'] . '"' . $post_id . ']' . implode(' ', $sub_fields) . "\r\n" . '[/e2pdf-acf-repeater') . '</div>';
2781 }
2782 } elseif ($field['type'] == 'group' && !empty($field['sub_fields'])) {
2783 $sub_fields = array();
2784 foreach ($field['sub_fields'] as $sub_field_key => $sub_field) {
2785 $sub_field['label'] = $field['label'] . ' ' . $sub_field['label'];
2786 $sub_field['name'] = $field['name'] . '_' . $sub_field['name'];
2787 $vc = $this->get_acf_field($vc, $sub_field, $post_id);
2788 }
2789 } else {
2790 if ($field['name']) {
2791 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($field['label'], 'acf field="' . $field['name'] . '"' . $post_id) . '</div>';
2792 }
2793 }
2794 return $vc;
2795 }
2796
2797 private function get_item_type_keys_subkeys($item_type = false) {
2798 global $wpdb;
2799
2800 $meta_data = $wpdb->get_results('SELECT DISTINCT `meta`.`meta_key`, `item`.`order_item_type` FROM `' . $wpdb->prefix . 'woocommerce_order_itemmeta` `meta` LEFT JOIN `' . $wpdb->prefix . 'woocommerce_order_items` `item` ON (`meta`.`order_item_id` = `item`.`order_item_id`)', ARRAY_A);
2801 $meta_keys = array();
2802 if ($meta_data) {
2803 foreach ($meta_data as $key => $meta) {
2804 if ($item_type) {
2805 if ($meta['order_item_type'] == $item_type) {
2806 $meta_keys[] = $meta['meta_key'];
2807 }
2808 } else {
2809 $field_key = array_search($meta['order_item_type'], array_column($meta_keys, 'meta_key'), false);
2810 if ($field_key === false) {
2811 $meta_keys[] = array(
2812 'meta_key' => $meta['order_item_type'],
2813 'sub_keys' => array(
2814 $meta['meta_key'],
2815 ),
2816 );
2817 } else {
2818 $meta_keys[$field_key]['sub_keys'][] = $meta['meta_key'];
2819 }
2820 }
2821 }
2822 }
2823
2824 return $meta_keys;
2825 }
2826
2827 private function get_post_taxonomy_keys() {
2828 global $wpdb;
2829
2830 $meta_keys = array();
2831 if ($this->get('item')) {
2832 $order_condition = array(
2833 'orderby' => 'taxonomy',
2834 'order' => 'desc',
2835 );
2836 $orderby = $this->helper->load('db')->prepare_orderby($order_condition);
2837 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
2838 $meta_keys = $wpdb->get_col($wpdb->prepare('SELECT DISTINCT `taxonomy` FROM `' . $wpdb->term_taxonomy . '` `t` ' . $orderby . '', ''));
2839 }
2840
2841 return $meta_keys;
2842 }
2843
2844 private function get_post_meta_keys($item = false, $post_id = false) {
2845 global $wpdb;
2846
2847 if (!$item) {
2848 $item = $this->get('item');
2849 }
2850
2851 $meta_keys = array();
2852 if ($item || $post_id) {
2853 if (($item == 'shop_order' || $item == 'shop_subscription') && get_option('woocommerce_custom_orders_table_enabled') === 'yes' && get_option('woocommerce_custom_orders_table_data_sync_enabled') !== 'yes') {
2854 $order_condition = array(
2855 'orderby' => 'meta_key',
2856 'order' => 'desc',
2857 );
2858 $orderby = $this->helper->load('db')->prepare_orderby($order_condition);
2859 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
2860 $meta_keys = $wpdb->get_col($wpdb->prepare('SELECT DISTINCT `meta_key` FROM `' . $wpdb->prefix . 'wc_orders_meta` `pm` ' . $orderby . ''));
2861 if (class_exists('WC_Order_Data_Store_CPT')) {
2862 $internal_meta_keys = (new WC_Order_Data_Store_CPT())->get_internal_meta_keys();
2863 if (!empty($internal_meta_keys) && is_array($internal_meta_keys)) {
2864 $meta_keys = array_merge($meta_keys, $internal_meta_keys);
2865 }
2866 }
2867 } else {
2868 if ($post_id) {
2869 $condition = array(
2870 'p.ID' => array(
2871 'condition' => '=',
2872 'value' => $post_id,
2873 'type' => '%d',
2874 ),
2875 );
2876 } else {
2877 $condition = array(
2878 'p.post_type' => array(
2879 'condition' => '=',
2880 'value' => $item,
2881 'type' => '%s',
2882 ),
2883 );
2884 }
2885 $order_condition = array(
2886 'orderby' => 'meta_key',
2887 'order' => 'desc',
2888 );
2889 $where = $this->helper->load('db')->prepare_where($condition);
2890 $orderby = $this->helper->load('db')->prepare_orderby($order_condition);
2891 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
2892 $meta_keys = $wpdb->get_col($wpdb->prepare('SELECT DISTINCT `meta_key` FROM `' . $wpdb->postmeta . '` `pm` LEFT JOIN `' . $wpdb->posts . '` `p` ON (`p`.`ID` = `pm`.`post_ID`) ' . $where['sql'] . $orderby . '', $where['filter']));
2893 }
2894 }
2895
2896 return $meta_keys;
2897 }
2898
2899 private function get_product_attribute_keys() {
2900 global $wpdb;
2901
2902 $meta_keys = array();
2903 $attributes = wc_get_attribute_taxonomies();
2904 foreach ($attributes as $attribute) {
2905 $meta_keys[] = array(
2906 'id' => 'pa_' . $attribute->attribute_name,
2907 'name' => $attribute->attribute_label,
2908 );
2909 }
2910
2911 $condition = array(
2912 'pm.meta_key' => array(
2913 'condition' => '=',
2914 'value' => '_product_attributes',
2915 'type' => '%s',
2916 ),
2917 );
2918
2919 $order_condition = array(
2920 'orderby' => 'pm.meta_key',
2921 'order' => 'desc',
2922 );
2923
2924 $where = $this->helper->load('db')->prepare_where($condition);
2925 $orderby = $this->helper->load('db')->prepare_orderby($order_condition);
2926 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
2927 $custom_meta_keys = $wpdb->get_col($wpdb->prepare('SELECT DISTINCT `meta_value` FROM `' . $wpdb->postmeta . '` `pm`' . $where['sql'] . $orderby . '', $where['filter']));
2928 foreach ($custom_meta_keys as $custom_meta_key) {
2929 $custom_metas = $this->helper->load('convert')->unserialize($custom_meta_key);
2930 if ($custom_metas && is_array($custom_metas)) {
2931 foreach ($custom_metas as $custom_metas_key => $custom_metas_value) {
2932 if (isset($custom_metas_value['is_taxonomy']) && $custom_metas_value['is_taxonomy']) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
2933 } else {
2934 $in_array = array_search($custom_metas_key, array_column($meta_keys, 'id'), false);
2935 if ($in_array === false && isset($custom_metas_value['name'])) {
2936 $meta_keys[] = array(
2937 'id' => $custom_metas_key,
2938 'name' => $custom_metas_value['name'],
2939 );
2940 }
2941 }
2942 }
2943 }
2944 }
2945
2946 return $meta_keys;
2947 }
2948
2949 private function get_vm_element($name, $id) {
2950 $element = '<div>';
2951 $element .= '<label>' . $name . ':</label>';
2952 $element .= '<input type="text" name=\'[' . $id . ']\' value=\'[' . $id . ']\' class="e2pdf-w100">';
2953 $element .= '</div>';
2954 return $element;
2955 }
2956
2957 private function get_vm_product() {
2958
2959 $index = '';
2960 if ($this->get('item') == 'shop_order' || $this->get('item') == 'shop_subscription' || $this->get('item') == 'cart') {
2961 $index = ' index="0"';
2962 }
2963
2964 $vc = '';
2965
2966 $vc .= '<h3 class="e2pdf-plr5">Product</h3>';
2967 $vc .= '<div class="e2pdf-grid">';
2968 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Name', 'e2pdf-wc-product key="get_name"' . $index) . '</div>';
2969 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Type', 'e2pdf-wc-product key="get_type"' . $index) . '</div>';
2970 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Slug', 'e2pdf-wc-product key="get_slug"' . $index) . '</div>';
2971 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date Created', 'e2pdf-wc-product key="get_date_created"' . $index) . '</div>';
2972 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date Modified', 'e2pdf-wc-product key="get_date_modified"' . $index) . '</div>';
2973 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Status', 'e2pdf-wc-product key="get_status"' . $index) . '</div>';
2974 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Featured', 'e2pdf-wc-product key="get_featured"' . $index) . '</div>';
2975 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Catalog Visibility', 'e2pdf-wc-product key="get_catalog_visibility"' . $index) . '</div>';
2976 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Description', 'e2pdf-wc-product key="get_description" wc_format_content="true"' . $index) . '</div>';
2977 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Short Description', 'e2pdf-wc-product key="get_short_description" wc_format_content="true"' . $index) . '</div>';
2978 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Sku', 'e2pdf-wc-product key="get_sku"' . $index) . '</div>';
2979 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Price', 'e2pdf-wc-product key="get_price"' . $index) . '</div>';
2980 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Regular Price', 'e2pdf-wc-product key="get_regular_price"' . $index) . '</div>';
2981 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Sale Price', 'e2pdf-wc-product key="get_sale_price"' . $index) . '</div>';
2982 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date Sale From', 'e2pdf-wc-product key="get_date_on_sale_from"' . $index) . '</div>';
2983 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date Sale To', 'e2pdf-wc-product key="get_date_on_sale_to"' . $index) . '</div>';
2984 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Total Sales', 'e2pdf-wc-product key="get_total_sales"' . $index) . '</div>';
2985 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Tax Status', 'e2pdf-wc-product key="get_tax_status"' . $index) . '</div>';
2986 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Tax Class', 'e2pdf-wc-product key="get_tax_class"' . $index) . '</div>';
2987 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Manage Stock', 'e2pdf-wc-product key="get_manage_stock"' . $index) . '</div>';
2988 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Stock Quantity', 'e2pdf-wc-product key="get_stock_quantity"' . $index) . '</div>';
2989 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Stock Status', 'e2pdf-wc-product key="get_stock_status"' . $index) . '</div>';
2990 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Backorders', 'e2pdf-wc-product key="get_backorders"' . $index) . '</div>';
2991 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Low Stock Amount', 'e2pdf-wc-product key="get_low_stock_amount"' . $index) . '</div>';
2992 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Sold Individually', 'e2pdf-wc-product key="get_sold_individually"' . $index) . '</div>';
2993 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Weight', 'e2pdf-wc-product key="get_weight"' . $index) . '</div>';
2994 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Length', 'e2pdf-wc-product key="get_length"' . $index) . '</div>';
2995 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Width', 'e2pdf-wc-product key="get_width"' . $index) . '</div>';
2996 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Height', 'e2pdf-wc-product key="get_height"' . $index) . '</div>';
2997 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Dimensions', 'e2pdf-wc-product key="get_dimensions"' . $index) . '</div>';
2998 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Upsell IDs', 'e2pdf-wc-product key="get_upsell_ids"' . $index) . '</div>';
2999 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cross Sell IDs', 'e2pdf-wc-product key="get_cross_sell_ids"' . $index) . '</div>';
3000 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Parent ID', 'e2pdf-wc-product key="get_parent_id"' . $index) . '</div>';
3001 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Reviews Allowed', 'e2pdf-wc-product key="get_reviews_allowed"' . $index) . '</div>';
3002 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Purchase Note', 'e2pdf-wc-product key="get_purchase_note"' . $index) . '</div>';
3003 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Attributes', 'e2pdf-wc-product key="get_attributes"' . $index) . '</div>';
3004 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Default Attributes', 'e2pdf-wc-product key="get_default_attributes"' . $index) . '</div>';
3005 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Menu Order', 'e2pdf-wc-product key="get_menu_order"' . $index) . '</div>';
3006 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Password', 'e2pdf-wc-product key="get_post_password"' . $index) . '</div>';
3007 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Category IDs', 'e2pdf-wc-product key="get_category_ids"' . $index) . '</div>';
3008 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Tag IDs', 'e2pdf-wc-product key="get_tag_ids"' . $index) . '</div>';
3009 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Virtual', 'e2pdf-wc-product key="get_virtual"' . $index) . '</div>';
3010 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Gallery Image IDs', 'e2pdf-wc-product key="get_gallery_image_ids"' . $index) . '</div>';
3011 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Class ID', 'e2pdf-wc-product key="get_shipping_class_id"' . $index) . '</div>';
3012 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Downloads', 'e2pdf-wc-product key="get_downloads"' . $index) . '</div>';
3013 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Download Expiry', 'e2pdf-wc-product key="get_download_expiry"' . $index) . '</div>';
3014 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Downloadable', 'e2pdf-wc-product key="get_downloadable"' . $index) . '</div>';
3015 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Download Limit', 'e2pdf-wc-product key="get_download_limit"' . $index) . '</div>';
3016 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Image ID', 'e2pdf-wc-product key="get_image_id"' . $index) . '</div>';
3017 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Rating Counts', 'e2pdf-wc-product key="get_rating_counts"' . $index) . '</div>';
3018 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Average Rating', 'e2pdf-wc-product key="get_average_rating"' . $index) . '</div>';
3019 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Review Count', 'e2pdf-wc-product key="get_review_count"' . $index) . '</div>';
3020 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Title', 'e2pdf-wc-product key="get_title"' . $index) . '</div>';
3021 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Product Permalink', 'e2pdf-wc-product key="get_permalink"' . $index) . '</div>';
3022 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Children', 'e2pdf-wc-product key="get_children"' . $index) . '</div>';
3023 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Stock Managed ID', 'e2pdf-wc-product key="get_stock_managed_by_id"' . $index) . '</div>';
3024 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Price (HTML)', 'e2pdf-wc-product key="get_price_html"' . $index) . '</div>';
3025 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Formatted Name', 'e2pdf-wc-product key="get_formatted_name"' . $index) . '</div>';
3026 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Min Purchase Quantity', 'e2pdf-wc-product key="get_min_purchase_quantity"' . $index) . '</div>';
3027 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Max Purchase Quantity', 'e2pdf-wc-product key="get_max_purchase_quantity"' . $index) . '</div>';
3028 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Image', 'e2pdf-wc-product key="get_image"' . $index) . '</div>';
3029 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Class', 'e2pdf-wc-product key="get_shipping_class"' . $index) . '</div>';
3030 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Rating Count', 'e2pdf-wc-product key="get_rating_count"' . $index) . '</div>';
3031 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('File', 'e2pdf-wc-product key="get_file"' . $index) . '</div>';
3032 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('File Download Path', 'e2pdf-wc-product key="get_file_download_path"' . $index) . '</div>';
3033 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Price Suffix', 'e2pdf-wc-product key="get_price_suffix"' . $index) . '</div>';
3034 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Availability', 'e2pdf-wc-product key="get_availability"' . $index) . '</div>';
3035 if ($this->get('item') == 'product_variation') {
3036 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Product Variation Attributes', 'e2pdf-wc-product key="get_variation_attributes"' . $index) . '</div>';
3037 }
3038 $vc .= '</div>';
3039
3040 $vc .= '<h3 class="e2pdf-plr5">Product Common</h3>';
3041 $vc .= '<div class="e2pdf-grid">';
3042 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('ID', 'e2pdf-wc-product key="id"' . $index) . '</div>';
3043 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Author', 'e2pdf-wc-product key="post_author"' . $index) . '</div>';
3044 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Author ID', 'e2pdf-wc-product key="post_author_id"' . $index) . '</div>';
3045 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date', 'e2pdf-wc-product key="post_date"' . $index) . '</div>';
3046 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date (GMT)', 'e2pdf-wc-product key="post_date_gmt"' . $index) . '</div>';
3047 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Content', 'e2pdf-wc-product key="post_content"' . $index) . '</div>';
3048 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Title', 'e2pdf-wc-product key="post_title"' . $index) . '</div>';
3049 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Excerpt', 'e2pdf-wc-product key="post_excerpt"' . $index) . '</div>';
3050 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Status', 'e2pdf-wc-product key="post_status"' . $index) . '</div>';
3051 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Comment Status', 'e2pdf-wc-product key="comment_status"' . $index) . '</div>';
3052 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Ping Status', 'e2pdf-wc-product key="ping_status"' . $index) . '</div>';
3053 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Password', 'e2pdf-wc-product key="post_password"' . $index) . '</div>';
3054 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Name', 'e2pdf-wc-product key="post_name"' . $index) . '</div>';
3055 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('To Ping', 'e2pdf-wc-product key="to_ping"' . $index) . '</div>';
3056 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Ping', 'e2pdf-wc-product key="pinged"' . $index) . '</div>';
3057 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Modified Date', 'e2pdf-wc-product key="post_modified"' . $index) . '</div>';
3058 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Modified Date (GMT)', 'e2pdf-wc-product key="post_modified_gmt"' . $index) . '</div>';
3059 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Filtered Content', 'e2pdf-wc-product key="post_content_filtered"' . $index) . '</div>';
3060 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Parent ID', 'e2pdf-wc-product key="post_parent"' . $index) . '</div>';
3061 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('GUID', 'e2pdf-wc-product key="guid"' . $index) . '</div>';
3062 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Menu Order', 'e2pdf-wc-product key="menu_order"' . $index) . '</div>';
3063 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Type', 'e2pdf-wc-product key="post_type"' . $index) . '</div>';
3064 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Mime Type', 'e2pdf-wc-product key="post_mime_type"' . $index) . '</div>';
3065 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Comments Count', 'e2pdf-wc-product key="comment_count"' . $index) . '</div>';
3066 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Filter', 'e2pdf-wc-product key="filter"' . $index) . '</div>';
3067 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Post Thumbnail', 'e2pdf-wc-product key="get_the_post_thumbnail"' . $index) . '</div>';
3068 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Post Thumbnail URL', 'e2pdf-wc-product key="get_the_post_thumbnail_url"' . $index) . '</div>';
3069 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Permalink', 'e2pdf-wc-product key="permalink"' . $index) . '</div>';
3070 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Post Permalink', 'e2pdf-wc-product key="get_post_permalink"' . $index) . '</div>';
3071 $vc .= '</div>';
3072
3073 $meta_keys = $this->get_product_attribute_keys();
3074 $vc .= '<h3 class="e2pdf-plr5">Product Attributes</h3>';
3075 $vc .= '<div class="e2pdf-grid">';
3076 $i = 0;
3077 foreach ($meta_keys as $meta_key) {
3078 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($meta_key['name'], 'e2pdf-wc-product key="get_attribute" attribute="' . $meta_key['id'] . '" show="value"' . $index) . '</div>';
3079
3080 $i++;
3081 }
3082 $vc .= '</div>';
3083
3084 $vc .= '<h3 class="e2pdf-plr5">Product Special Shortcodes</h3>';
3085 $vc .= '<div class="e2pdf-grid">';
3086 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Product Attributes', 'e2pdf-foreach shortcode="e2pdf-wc-product" key="get_attributes"' . $index . ' wc_filter="true"][e2pdf-wc-product key="get_attributes" path="[e2pdf-foreach-key].label" wc_filter="true"' . $index . ']: [e2pdf-wc-product key="get_attributes" path="[e2pdf-foreach-key].value" wc_filter="true"' . $index . ']' . "\r\n" . '[/e2pdf-foreach') . '</div>';
3087 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Formatted Meta Data', 'e2pdf-foreach shortcode="e2pdf-wc-product" key="get_formatted_meta_data"' . $index . '][e2pdf-wc-product key="get_formatted_meta_data" path="[e2pdf-foreach-key].display_key"' . $index . ']:[e2pdf-wc-product key="get_formatted_meta_data" path="[e2pdf-foreach-key].display_value"' . $index . ']' . "\r\n" . '[/e2pdf-foreach') . '</div>';
3088 if ($this->get('item') == 'product_variation') {
3089 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Product Variation Attributes', 'e2pdf-foreach shortcode="e2pdf-wc-product" key="get_variation_attributes"' . $index . ' wc_filter="true"][e2pdf-wc-product key="get_variation_attributes" path="[e2pdf-foreach-key].label" wc_filter="true"' . $index . ']: [e2pdf-wc-product key="get_variation_attributes" path="[e2pdf-foreach-key].value" wc_filter="true"' . $index . ']' . "\r\n" . '[/e2pdf-foreach') . '</div>';
3090 }
3091
3092 $vc .= '</div>';
3093
3094 $meta_keys = $this->get_post_meta_keys('product');
3095 $meta_keys2 = $this->get_post_meta_keys('product_variation');
3096
3097 if (!empty($meta_keys2)) {
3098 foreach ($meta_keys2 as $meta_key) {
3099 if (!in_array($meta_key, $meta_keys, false)) {
3100 $meta_keys[] = $meta_key;
3101 }
3102 }
3103 }
3104
3105 if (!empty($meta_keys)) {
3106 $vc .= '<h3 class="e2pdf-plr5">Product Meta Keys</h3>';
3107 $vc .= '<div class="e2pdf-grid">';
3108 $i = 0;
3109 foreach ($meta_keys as $meta_key) {
3110 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($meta_key, 'e2pdf-wc-product key="' . $meta_key . '" meta="true"' . $index) . '</div>';
3111 $i++;
3112 }
3113 $vc .= '</div>';
3114 }
3115
3116 $meta_keys = $this->get_post_taxonomy_keys();
3117 if (!empty($meta_keys)) {
3118 $vc .= '<h3 class="e2pdf-plr5">Product Taxonomy</h3>';
3119 $vc .= '<div class="e2pdf-grid">';
3120 $i = 0;
3121 foreach ($meta_keys as $meta_key) {
3122 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($meta_key, 'e2pdf-wc-product key="' . $meta_key . '" terms="true" names="true"' . $index) . '</div>';
3123 $i++;
3124 }
3125 $vc .= '</div>';
3126 }
3127
3128 return $vc;
3129 }
3130
3131 private function get_vm_product_order() {
3132 $index = '';
3133 if ($this->get('item') == 'shop_order' || $this->get('item') == 'shop_subscription' || $this->get('item') == 'cart') {
3134 $index = ' index="0"';
3135 }
3136
3137 $vc = '';
3138
3139 if ($this->get('item') == 'cart') {
3140 $vc .= '<h3 class="e2pdf-plr5">Cart Product</h3>';
3141 } else {
3142 $vc .= '<h3 class="e2pdf-plr5">Order Product</h3>';
3143 }
3144 $vc .= '<div class="e2pdf-grid">';
3145 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Name', 'e2pdf-wc-product key="get_name" order="true"' . $index) . '</div>';
3146 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Type', 'e2pdf-wc-product key="get_type" order="true"' . $index) . '</div>';
3147 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Quantity', 'e2pdf-wc-product key="get_quantity" order="true"' . $index) . '</div>';
3148 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Tax Status', 'e2pdf-wc-product key="get_tax_status" order="true"' . $index) . '</div>';
3149 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Tax Class', 'e2pdf-wc-product key="get_tax_class" order="true"' . $index) . '</div>';
3150 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Formatted Meta Data', 'e2pdf-wc-product key="get_formatted_meta_data" order="true"' . $index) . '</div>';
3151 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Product ID', 'e2pdf-wc-product key="get_product_id" order="true"' . $index) . '</div>';
3152 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Variation ID', 'e2pdf-wc-product key="get_variation_id" order="true"' . $index) . '</div>';
3153 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Subtotal', 'e2pdf-wc-product key="get_subtotal" order="true"' . $index) . '</div>';
3154 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Subtotal Tax', 'e2pdf-wc-product key="get_subtotal_tax" order="true"' . $index) . '</div>';
3155 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Total', 'e2pdf-wc-product key="get_total" order="true"' . $index) . '</div>';
3156 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Total Tax', 'e2pdf-wc-product key="get_total_tax" order="true"' . $index) . '</div>';
3157 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Taxes', 'e2pdf-wc-product key="get_taxes" order="true"' . $index) . '</div>';
3158 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Item Download URL', 'e2pdf-wc-product key="get_item_download_url" order="true" index="0" download_order="true"' . $index) . '</div>';
3159 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Downloads', 'e2pdf-wc-product key="get_item_downloads" order="true"' . $index) . '</div>';
3160 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Item Subtotal', 'e2pdf-wc-product key="get_item_subtotal" order="true"' . $index) . '</div>';
3161 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Item Total', 'e2pdf-wc-product key="get_item_total" order="true"' . $index) . '</div>';
3162 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Item Tax', 'e2pdf-wc-product key="get_item_tax" order="true"' . $index) . '</div>';
3163 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Line Total', 'e2pdf-wc-product key="get_line_total" order="true"' . $index) . '</div>';
3164 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Line Tax', 'e2pdf-wc-product key="get_line_tax" order="true"' . $index) . '</div>';
3165 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Formatted Line Subtotal', 'e2pdf-wc-product key="get_formatted_line_subtotal" order="true"' . $index) . '</div>';
3166 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Order Item ID', 'e2pdf-wc-product key="get_order_item_id" order="true"' . $index) . '</div>';
3167 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Order Response Hook', 'e2pdf-wc-product key="order_response_hook" order="true"' . $index) . '</div>';
3168
3169 if ($this->get('item') == 'cart') {
3170 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Item Cart Response Hook', 'e2pdf-wc-product key="item_cart_response_hook"' . $index) . '</div>';
3171 } else {
3172 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Item Response Hook', 'e2pdf-wc-product key="item_response_hook" order="true"' . $index) . '</div>';
3173 }
3174
3175 $vc .= '</div>';
3176
3177 return $vc;
3178 }
3179
3180 private function get_vm_product_order_item_meta() {
3181
3182 $index = '';
3183 if ($this->get('item') == 'shop_order' || $this->get('item') == 'shop_subscription' || $this->get('item') == 'cart') {
3184 $index = ' index="0"';
3185 }
3186
3187 $vc = '';
3188 $meta_keys = $this->get_item_type_keys_subkeys('line_item');
3189 if (!empty($meta_keys)) {
3190 $vc .= '<h3 class="e2pdf-plr5">Order Product Item Meta Keys</h3>';
3191 $vc .= '<div class="e2pdf-grid">';
3192 $i = 0;
3193 foreach ($meta_keys as $meta_key) {
3194 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($meta_key, 'e2pdf-wc-product key="' . $meta_key . '" order_item_meta="true"' . $index) . '</div>';
3195 $i++;
3196 }
3197 $vc .= '</div>';
3198 }
3199
3200 return $vc;
3201 }
3202
3203 private function get_vm_order($post_type = 'shop_order') {
3204
3205 $vc = '';
3206 $vc .= '<h3 class="e2pdf-plr5">Order</h3>';
3207 $vc .= '<div class="e2pdf-grid">';
3208 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Order ID', 'e2pdf-wc-order key="get_id"') . '</div>';
3209 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Order Key', 'e2pdf-wc-order key="get_order_key"') . '</div>';
3210 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Order Number', 'e2pdf-wc-order key="get_order_number"') . '</div>';
3211 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Formatted Order Total', 'e2pdf-wc-order key="get_formatted_order_total"') . '</div>';
3212 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cart Tax', 'e2pdf-wc-order key="get_cart_tax"') . '</div>';
3213 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Currency', 'e2pdf-wc-order key="get_currency"') . '</div>';
3214 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Discount Tax', 'e2pdf-wc-order key="get_discount_tax"') . '</div>';
3215 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Discount to Display', 'e2pdf-wc-order key="get_discount_to_display"') . '</div>';
3216 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Discount Total', 'e2pdf-wc-order key="get_discount_total"') . '</div>';
3217 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Tax', 'e2pdf-wc-order key="get_shipping_tax"') . '</div>';
3218 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Total', 'e2pdf-wc-order key="get_shipping_total"') . '</div>';
3219 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Subtotal', 'e2pdf-wc-order key="get_subtotal"') . '</div>';
3220 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Subtotal to Display', 'e2pdf-wc-order key="get_subtotal_to_display"') . '</div>';
3221 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Get Total', 'e2pdf-wc-order key="get_total"') . '</div>';
3222 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Total Discount', 'e2pdf-wc-order key="get_total_discount"') . '</div>';
3223 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Total Tax', 'e2pdf-wc-order key="get_total_tax"') . '</div>';
3224 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Total Refunded', 'e2pdf-wc-order key="get_total_refunded"') . '</div>';
3225 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Total Tax Refunded', 'e2pdf-wc-order key="get_total_tax_refunded"') . '</div>';
3226 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Total Shipping Refunded', 'e2pdf-wc-order key="get_total_shipping_refunded"') . '</div>';
3227 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Item Count Refunded', 'e2pdf-wc-order key="get_item_count_refunded"') . '</div>';
3228 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Total QTY Refunded', 'e2pdf-wc-order key="get_total_qty_refunded"') . '</div>';
3229 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Remaining Refund Amount', 'e2pdf-wc-order key="get_remaining_refund_amount"') . '</div>';
3230 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Item Count', 'e2pdf-wc-order key="get_item_count"') . '</div>';
3231 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Method', 'e2pdf-wc-order key="get_shipping_method"') . '</div>';
3232 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping to Display', 'e2pdf-wc-order key="get_shipping_to_display"') . '</div>';
3233 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date Created', 'e2pdf-wc-order key="get_date_created"') . '</div>';
3234 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date Modified', 'e2pdf-wc-order key="get_date_modified"') . '</div>';
3235 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date Completed', 'e2pdf-wc-order key="get_date_completed"') . '</div>';
3236 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date Paid', 'e2pdf-wc-order key="get_date_paid"') . '</div>';
3237 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Custom ID', 'e2pdf-wc-order key="get_customer_id"') . '</div>';
3238 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('User ID', 'e2pdf-wc-order key="get_user_id"') . '</div>';
3239 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Customer IP Address', 'e2pdf-wc-order key="get_customer_ip_address"') . '</div>';
3240 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Customer User Agent', 'e2pdf-wc-order key="get_customer_user_agent"') . '</div>';
3241 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Created Via', 'e2pdf-wc-order key="get_created_via"') . '</div>';
3242 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Customer Note', 'e2pdf-wc-order key="get_customer_note"') . '</div>';
3243 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing First Name', 'e2pdf-wc-order key="get_billing_first_name"') . '</div>';
3244 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing Last Name', 'e2pdf-wc-order key="get_billing_last_name"') . '</div>';
3245 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing Company', 'e2pdf-wc-order key="get_billing_company"') . '</div>';
3246 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing Address 1', 'e2pdf-wc-order key="get_billing_address_1"') . '</div>';
3247 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing Address 2', 'e2pdf-wc-order key="get_billing_address_2"') . '</div>';
3248 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing City', 'e2pdf-wc-order key="get_billing_city"') . '</div>';
3249 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing State', 'e2pdf-wc-order key="get_billing_state"') . '</div>';
3250 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing Postcode', 'e2pdf-wc-order key="get_billing_postcode"') . '</div>';
3251 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing Country', 'e2pdf-wc-order key="get_billing_country"') . '</div>';
3252 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing E-mail', 'e2pdf-wc-order key="get_billing_email"') . '</div>';
3253 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Billing Phone', 'e2pdf-wc-order key="get_billing_phone"') . '</div>';
3254 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shopping First Name', 'e2pdf-wc-order key="get_shipping_first_name"') . '</div>';
3255 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Last Name', 'e2pdf-wc-order key="get_shipping_last_name"') . '</div>';
3256 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Company', 'e2pdf-wc-order key="get_shipping_company"') . '</div>';
3257 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Address 1', 'e2pdf-wc-order key="get_shipping_address_1"') . '</div>';
3258 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Address 2', 'e2pdf-wc-order key="get_shipping_address_2"') . '</div>';
3259 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping City', 'e2pdf-wc-order key="get_shipping_city"') . '</div>';
3260 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping State', 'e2pdf-wc-order key="get_shipping_state"') . '</div>';
3261 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Postcode', 'e2pdf-wc-order key="get_shipping_postcode"') . '</div>';
3262 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Country', 'e2pdf-wc-order key="get_shipping_country"') . '</div>';
3263 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Shipping Address Map URL', 'e2pdf-wc-order key="get_shipping_address_map_url"') . '</div>';
3264 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Formatted Billing Full Name', 'e2pdf-wc-order key="get_formatted_billing_full_name"') . '</div>';
3265 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Formatted Shipping Full Name', 'e2pdf-wc-order key="get_formatted_shipping_full_name"') . '</div>';
3266 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Formatted Billing Address', 'e2pdf-wc-order key="get_formatted_billing_address"') . '</div>';
3267 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Formatted Shipping Address', 'e2pdf-wc-order key="get_formatted_shipping_address"') . '</div>';
3268 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Payment Method', 'e2pdf-wc-order key="get_payment_method"') . '</div>';
3269 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Payment Method Title', 'e2pdf-wc-order key="get_payment_method_title"') . '</div>';
3270 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Transaction ID', 'e2pdf-wc-order key="get_transaction_id"') . '</div>';
3271 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Checkout Payment URL', 'e2pdf-wc-order key="get_checkout_payment_url"') . '</div>';
3272 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Checkout Order Received URL', 'e2pdf-wc-order key="get_checkout_order_received_url"') . '</div>';
3273 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cancel Order URL', 'e2pdf-wc-order key="get_cancel_order_url"') . '</div>';
3274 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cancel Order URL (raw)', 'e2pdf-wc-order key="get_cancel_order_url_raw"') . '</div>';
3275 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cancel Endpoint', 'e2pdf-wc-order key="get_cancel_endpoint"') . '</div>';
3276 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('View Order URL', 'e2pdf-wc-order key="get_view_order_url"') . '</div>';
3277 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Edit Order URL', 'e2pdf-wc-order key="get_edit_order_url"') . '</div>';
3278 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Status', 'e2pdf-wc-order key="get_status"') . '</div>';
3279 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Items IDs', 'e2pdf-wc-order key="get_items_ids"') . '</div>';
3280 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Items Category', 'e2pdf-wc-order key="get_items_category"') . '</div>';
3281 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Items Category IDs', 'e2pdf-wc-order key="get_items_category_ids"') . '</div>';
3282 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Cart', 'e2pdf-wc-order key="cart"') . '</div>';
3283 $vc .= '</div>';
3284
3285 $vc .= '<h3 class="e2pdf-plr5">Order Special Shortcodes</h3>';
3286 $vc .= '<div class="e2pdf-grid">';
3287 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Order Products', 'e2pdf-foreach shortcode="e2pdf-wc-order" key="get_items"][e2pdf-wc-product key="get_name" order="true" index="[e2pdf-foreach-index]"]' . "\r\n" . '[/e2pdf-foreach') . '</div>';
3288 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Order Totals', 'e2pdf-foreach shortcode="e2pdf-wc-order" key="get_order_item_totals"][e2pdf-wc-order key="get_order_item_totals" path="[e2pdf-foreach-key].label"][e2pdf-wc-order key="get_order_item_totals" path="[e2pdf-foreach-key].value"]' . "\r\n" . '[/e2pdf-foreach') . '</div>';
3289
3290 $vc .= '</div>';
3291
3292 $meta_keys = $this->get_post_meta_keys($post_type);
3293 if (!empty($meta_keys)) {
3294 $vc .= '<h3 class="e2pdf-plr5">Order Meta Keys</h3>';
3295 $vc .= '<div class="e2pdf-grid">';
3296 $i = 0;
3297 foreach ($meta_keys as $meta_key) {
3298 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($meta_key, 'e2pdf-wc-order key="' . $meta_key . '" meta="true"') . '</div>';
3299 $i++;
3300 }
3301 $vc .= '</div>';
3302 }
3303
3304 /*
3305 * Checkout Field Editor (Checkout Manager) for WooCommerce
3306 * https://wordpress.org/plugins/woo-checkout-field-editor-pro/
3307 */
3308 $meta_keys = [];
3309 if (class_exists('WCFE_Checkout_Fields_Utils') && class_exists('THWCFE_Utils_Section')) {
3310 $checkout_field_editor_sections = WCFE_Checkout_Fields_Utils::get_checkout_sections();
3311 foreach ($checkout_field_editor_sections as $checkout_field_editor_section) {
3312 $checkout_field_editor_fields = THWCFE_Utils_Section::get_fields($checkout_field_editor_section);
3313 $meta_keys = array_merge($meta_keys, $checkout_field_editor_fields);
3314 }
3315 }
3316 if (class_exists('THWCFD_Utils')) {
3317 $meta_keys = array_merge(
3318 $meta_keys,
3319 THWCFD_Utils::get_fields('billing'),
3320 THWCFD_Utils::get_fields('shipping'),
3321 THWCFD_Utils::get_fields('additional')
3322 );
3323 }
3324 if (class_exists('THWCFD_Utils_Block') && class_exists('THWCFE_Utils_Section')) {
3325 $checkout_field_editor_sections = THWCFD_Utils_Block::get_block_checkout_sections();
3326 foreach ($checkout_field_editor_sections as $checkout_field_editor_section) {
3327 $checkout_field_editor_fields = THWCFE_Utils_Section::get_fields($checkout_field_editor_section);
3328 $meta_keys = array_merge($meta_keys, $checkout_field_editor_fields);
3329 }
3330 }
3331 if (class_exists('THWCFD_Utils_Block') && class_exists('THWCFD_Utils_Section')) {
3332 $checkout_field_editor_sections = THWCFD_Utils_Block::get_block_checkout_sections();
3333 foreach ($checkout_field_editor_sections as $checkout_field_editor_section) {
3334 $checkout_field_editor_fields = THWCFD_Utils_Section::get_fieldset($checkout_field_editor_section);
3335 $meta_keys = array_merge($meta_keys, $checkout_field_editor_fields);
3336 }
3337 }
3338 if (!empty($meta_keys)) {
3339 $vc .= '<h3 class="e2pdf-plr5">Checkout Field Editor for WooCommerce</h3>';
3340 $vc .= '<div class="e2pdf-grid">';
3341 $i = 0;
3342 foreach ($meta_keys as $meta_key => $meta_value) {
3343 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($meta_key, 'e2pdf-wc-order key="' . $meta_key . '" meta="true" checkout_field_editor="true"') . '</div>';
3344 $i++;
3345 }
3346 $vc .= '</div>';
3347 }
3348
3349 $meta_keys = $this->get_post_taxonomy_keys();
3350 if (!empty($meta_keys)) {
3351 $vc .= '<h3 class="e2pdf-plr5">Order Taxonomy</h3>';
3352 $vc .= '<div class="e2pdf-grid">';
3353 $i = 0;
3354 foreach ($meta_keys as $meta_key) {
3355 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($meta_key, 'e2pdf-wc-order key="' . $meta_key . '" terms="true" names="true"') . '</div>';
3356 $i++;
3357 }
3358 $vc .= '</div>';
3359 }
3360
3361 $meta_keys = $this->get_item_type_keys_subkeys();
3362 if (!empty($meta_keys)) {
3363 $vc .= '<h3 class="e2pdf-plr5">Order Item Meta Keys</h3>';
3364 $vc .= '<div class="e2pdf-grid">';
3365
3366 $i = 0;
3367 foreach ($meta_keys as $meta_key) {
3368 foreach ($meta_key['sub_keys'] as $sub_key) {
3369 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($sub_key . ' (' . $meta_key['meta_key'] . ')', 'e2pdf-wc-order key="' . $meta_key['meta_key'] . '" subkey="' . $sub_key . '" index="0" order_item_meta="true"') . '</div>';
3370
3371 $i++;
3372 }
3373 }
3374 $vc .= '</div>';
3375 }
3376
3377 return $vc;
3378 }
3379
3380 public function get_vm_user() {
3381
3382 $vc = '<h3 class="e2pdf-plr5">User</h3>';
3383 $vc .= '<div class="e2pdf-grid">';
3384 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('ID', 'e2pdf-user key="ID"') . '</div>';
3385 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Description', 'e2pdf-user key="user_description"') . '</div>';
3386 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('First Name', 'e2pdf-user key="user_firstname"') . '</div>';
3387 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Last Name', 'e2pdf-user key="user_lastname"') . '</div>';
3388 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Login', 'e2pdf-user key="user_login"') . '</div>';
3389 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Nicename', 'e2pdf-user key="user_nicename"') . '</div>';
3390 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('E-mail', 'e2pdf-user key="user_email"') . '</div>';
3391 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Url', 'e2pdf-user key="user_url"') . '</div>';
3392 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Registered', 'e2pdf-user key="user_registered"') . '</div>';
3393 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('User Status', 'e2pdf-user key="user_status"') . '</div>';
3394 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('User Level', 'e2pdf-user key="user_level"') . '</div>';
3395 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Display Name', 'e2pdf-user key="display_name"') . '</div>';
3396 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Spam', 'e2pdf-user key="spam"') . '</div>';
3397 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Deleted', 'e2pdf-user key="deleted"') . '</div>';
3398 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Locale', 'e2pdf-user key="locale"') . '</div>';
3399 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Rich Editing', 'e2pdf-user key="rich_editing"') . '</div>';
3400 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Syntax Highlighting', 'e2pdf-user key="syntax_highlighting"') . '</div>';
3401 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Use SSL', 'e2pdf-user key="use_ssl"') . '</div>';
3402 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Roles', 'e2pdf-user key="roles"') . '</div>';
3403 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Avatar', 'e2pdf-user key="get_avatar"') . '</div>';
3404 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Avatar Url', 'e2pdf-user key="get_avatar_url"') . '</div>';
3405 $vc .= '</div>';
3406
3407 $meta_keys = $this->get_user_meta_keys();
3408 if (!empty($meta_keys)) {
3409 $vc .= '<h3 class="e2pdf-plr5">User Meta Keys</h3>';
3410 $vc .= '<div class="e2pdf-grid">';
3411 $i = 0;
3412 foreach ($meta_keys as $meta_key) {
3413 $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($meta_key, 'e2pdf-user key="' . $meta_key . '" meta="true"') . '</div>';
3414 $i++;
3415 }
3416 $vc .= '</div>';
3417 }
3418
3419 return $vc;
3420 }
3421
3422 private function get_user_meta_keys() {
3423 global $wpdb;
3424 $meta_keys = array();
3425 if ($this->get('item')) {
3426 $order_condition = array(
3427 'orderby' => 'meta_key',
3428 'order' => 'desc',
3429 );
3430 $orderby = $this->helper->load('db')->prepare_orderby($order_condition);
3431 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
3432 $meta_keys = $wpdb->get_col($wpdb->prepare('SELECT DISTINCT `meta_key` FROM `' . $wpdb->usermeta . '` ' . $orderby . ''));
3433 }
3434 return $meta_keys;
3435 }
3436
3437 public function action_e2pdf_wc_cart_template_id() {
3438 if (!is_cart() || WC()->cart->is_empty()) {
3439 return;
3440 }
3441 echo apply_filters(
3442 'e2pdf_wc_action_e2pdf_wc_cart_template_id',
3443 do_shortcode('[e2pdf-download id="' . get_option('e2pdf_wc_cart_template_id', '0') . '" dataset="' . wc_get_page_id('cart') . '" class="button e2pdf-wc-download-button e2pdf-wc-download-cart-button"]')
3444 );
3445 }
3446
3447 public function action_e2pdf_wc_checkout_template_id() {
3448 if (!is_checkout() || WC()->cart->is_empty()) {
3449 return;
3450 }
3451 echo apply_filters(
3452 'e2pdf_wc_action_e2pdf_wc_checkout_template_id',
3453 do_shortcode('[e2pdf-download id="' . get_option('e2pdf_wc_checkout_template_id', '0') . '" dataset="' . wc_get_page_id('cart') . '" class="button e2pdf-wc-download-button e2pdf-wc-download-checkout-button"]')
3454 );
3455 }
3456
3457 public function action_e2pdf_wc_order_details_template_id($order) {
3458 $statuses = get_option('e2pdf_wc_order_details_template_id_status', array('any'));
3459 if (is_array($statuses) && (in_array($order->get_status(), $statuses, false) || in_array('wc-' . $order->get_status(), $statuses, false) || in_array('any', $statuses, false))) {
3460 echo apply_filters(
3461 'e2pdf_wc_action_e2pdf_wc_order_details_template_id',
3462 do_shortcode('[e2pdf-download id="' . get_option('e2pdf_wc_order_details_template_id', '0') . '" dataset="' . $order->get_id() . '" class="button e2pdf-wc-download-button e2pdf-wc-download-order-details-button"]'),
3463 $order
3464 );
3465 }
3466 }
3467
3468 public function action_e2pdf_wc_admin_order_actions_template_id($order) {
3469 $statuses = get_option('e2pdf_wc_admin_order_actions_template_id_status', array('any'));
3470 if (is_array($statuses) && (in_array($order->get_status(), $statuses, false) || in_array('wc-' . $order->get_status(), $statuses, false) || in_array('any', $statuses, false))) {
3471 echo apply_filters(
3472 'e2pdf_wc_action_e2pdf_wc_admin_order_actions_template_id',
3473 do_shortcode('[e2pdf-download id="' . get_option('e2pdf_wc_admin_order_actions_template_id', '0') . '" dataset="' . $order->get_id() . '" user_id="' . $order->get_user_id() . '" class="button e2pdf-wc-download-button e2pdf-wc-download-order-details-button"]'),
3474 $order
3475 );
3476 }
3477 }
3478
3479 public function action_add_meta_boxes() {
3480 add_meta_box(
3481 'woocommerce-order-my-custom',
3482 'E2Pdf',
3483 array($this, 'action_e2pdf_wc_admin_order_details_template_id'),
3484 'shop_order',
3485 'side',
3486 'high'
3487 );
3488 }
3489
3490 public function action_e2pdf_wc_admin_order_details_template_id() {
3491 global $post;
3492 if (function_exists('wc_get_order') && isset($post->ID)) {
3493 $order = wc_get_order($post->ID);
3494 if ($order) {
3495 $statuses = get_option('e2pdf_wc_admin_order_details_template_id_status', array('any'));
3496 if (is_array($statuses) && (in_array($order->get_status(), $statuses, false) || in_array('wc-' . $order->get_status(), $statuses, false) || in_array('any', $statuses, false))) {
3497 echo apply_filters(
3498 'e2pdf_wc_action_e2pdf_wc_admin_order_details_template_id',
3499 do_shortcode('[e2pdf-download id="' . get_option('e2pdf_wc_admin_order_details_template_id', '0') . '" dataset="' . $order->get_id() . '" user_id="' . $order->get_user_id() . '" class="button e2pdf-wc-download-button e2pdf-wc-download-order-details-button"]'),
3500 $order
3501 );
3502 }
3503 }
3504 }
3505 }
3506
3507 public function filter_woocommerce_my_account_my_orders_actions($actions, $order) {
3508 $statuses = get_option('e2pdf_wc_my_orders_actions_template_id_status', array('any'));
3509 if (is_array($statuses) && (in_array($order->get_status(), $statuses, false) || in_array('wc-' . $order->get_status(), $statuses, false) || in_array('any', $statuses, false))) {
3510 $url = do_shortcode('[e2pdf-download id="' . get_option('e2pdf_wc_my_orders_actions_template_id', '0') . '" dataset="' . $order->get_id() . '" user_id="' . $order->get_user_id() . '" output="url"]');
3511 if ($url) {
3512 $actions['e2pdf_invoice'] = array(
3513 'url' => $url,
3514 'name' => apply_filters('e2pdf_wc_my_account_my_orders_actions_invoice_title', do_shortcode('[e2pdf-download id="' . get_option('e2pdf_wc_my_orders_actions_template_id', '0') . '" dataset="' . $order->get_id() . '" user_id="' . $order->get_user_id() . '" output="button_title"]')),
3515 );
3516 }
3517 $actions = apply_filters('e2pdf_wc_action_e2pdf_wc_my_orders_actions_template_id', $actions, $order);
3518 }
3519 return apply_filters('e2pdf_wc_filter_woocommerce_my_account_my_orders_actions', $actions, $order);
3520 }
3521
3522 /**
3523 * Add options for WooCommerce extension
3524 * @param array $options - List of options
3525 * @return array - Updated options list
3526 */
3527 public function filter_e2pdf_model_options_get_options_options($options = array()) {
3528 global $wpdb;
3529
3530 $model_e2pdf_template = new Model_E2pdf_Template();
3531
3532 $order_templates = array(
3533 '0' => __('--- Select ---', 'e2pdf'),
3534 );
3535 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
3536 $templates = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . $model_e2pdf_template->get_table() . '` WHERE extension = %s AND item = %s AND activated = %s ORDER BY ID ASC', 'woocommerce', 'shop_order', '1'), ARRAY_A);
3537 if (!empty($templates)) {
3538 foreach ($templates as $template) {
3539 $order_templates[$template['ID']] = $template['title'];
3540 }
3541 }
3542
3543 $cart_templates = array(
3544 '0' => __('--- Select ---', 'e2pdf'),
3545 );
3546 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
3547 $templates = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . $model_e2pdf_template->get_table() . '` WHERE extension = %s AND item = %s AND activated = %s ORDER BY ID ASC', 'woocommerce', 'cart', '1'), ARRAY_A);
3548
3549 if (!empty($templates)) {
3550 foreach ($templates as $template) {
3551 $cart_templates[$template['ID']] = $template['title'];
3552 }
3553 }
3554
3555 $options['woocommerce_group'] = array(
3556 'name' => 'WooCommerce',
3557 'action' => 'extension',
3558 'group' => 'woocommerce_group',
3559 'options' => array(
3560 array(
3561 'header' => __('User Order List', 'e2pdf'),
3562 'name' => __('Template', 'e2pdf'),
3563 'key' => 'e2pdf_wc_my_orders_actions_template_id',
3564 'value' => get_option('e2pdf_wc_my_orders_actions_template_id', '0'),
3565 'default_value' => '0',
3566 'type' => 'select',
3567 'options' => $order_templates,
3568 ),
3569 array(
3570 'name' => __('Order Status', 'e2pdf'),
3571 'key' => 'e2pdf_wc_my_orders_actions_template_id_status',
3572 'type' => 'checkbox_list',
3573 'options' => $this->get_status_options('e2pdf_wc_my_orders_actions_template_id'),
3574 ),
3575 array(
3576 'name' => __('Priority', 'e2pdf'),
3577 'key' => 'e2pdf_wc_my_orders_actions_template_id_priority',
3578 'value' => get_option('e2pdf_wc_my_orders_actions_template_id_priority', '10'),
3579 'default_value' => '10',
3580 'type' => 'text',
3581 'class' => 'e2pdf-numbers',
3582 'placeholder' => '0',
3583 ),
3584 array(
3585 'header' => __('User Order Details', 'e2pdf'),
3586 'name' => __('Template', 'e2pdf'),
3587 'key' => 'e2pdf_wc_order_details_template_id',
3588 'value' => get_option('e2pdf_wc_order_details_template_id', '0'),
3589 'default_value' => '0',
3590 'type' => 'select',
3591 'options' => $order_templates,
3592 ),
3593 array(
3594 'name' => __('Order Status', 'e2pdf'),
3595 'key' => 'e2pdf_wc_order_details_template_id_status',
3596 'type' => 'checkbox_list',
3597 'options' => $this->get_status_options('e2pdf_wc_order_details_template_id'),
3598 ),
3599 array(
3600 'name' => __('Hook', 'e2pdf'),
3601 'key' => 'e2pdf_wc_order_details_template_id_hook',
3602 'value' => get_option('e2pdf_wc_order_details_template_id_hook', 'woocommerce_order_details_before_order_table'),
3603 'default_value' => 'woocommerce_order_details_before_order_table',
3604 'type' => 'select',
3605 'options' => array(
3606 'woocommerce_order_details_before_order_table' => 'woocommerce_order_details_before_order_table',
3607 'woocommerce_order_details_before_order_table_items' => 'woocommerce_order_details_before_order_table_items',
3608 'woocommerce_order_details_after_order_table_items' => 'woocommerce_order_details_after_order_table_items',
3609 'woocommerce_order_details_after_order_table' => 'woocommerce_order_details_after_order_table',
3610 'woocommerce_after_order_details' => 'woocommerce_after_order_details',
3611 ),
3612 ),
3613 array(
3614 'name' => __('Priority', 'e2pdf'),
3615 'key' => 'e2pdf_wc_order_details_template_id_priority',
3616 'value' => get_option('e2pdf_wc_order_details_template_id_priority', '10'),
3617 'default_value' => '10',
3618 'type' => 'text',
3619 'class' => 'e2pdf-numbers',
3620 'placeholder' => '0',
3621 ),
3622 array(
3623 'header' => __('User Cart', 'e2pdf'),
3624 'name' => __('Template', 'e2pdf'),
3625 'key' => 'e2pdf_wc_cart_template_id',
3626 'value' => get_option('e2pdf_wc_cart_template_id', '0'),
3627 'default_value' => '0',
3628 'type' => 'select',
3629 'options' => $cart_templates,
3630 ),
3631 array(
3632 'name' => __('Priority', 'e2pdf'),
3633 'key' => 'e2pdf_wc_cart_template_id_priority',
3634 'value' => get_option('e2pdf_wc_cart_template_id_priority', '10'),
3635 'default_value' => '10',
3636 'type' => 'text',
3637 'class' => 'e2pdf-numbers',
3638 'placeholder' => '0',
3639 ),
3640 array(
3641 'header' => __('User Checkout', 'e2pdf'),
3642 'name' => __('Template', 'e2pdf'),
3643 'key' => 'e2pdf_wc_checkout_template_id',
3644 'value' => get_option('e2pdf_wc_checkout_template_id', '0'),
3645 'default_value' => '0',
3646 'type' => 'select',
3647 'options' => $cart_templates,
3648 ),
3649 array(
3650 'name' => __('Hook', 'e2pdf'),
3651 'key' => 'e2pdf_wc_checkout_template_id_hook',
3652 'value' => get_option('e2pdf_wc_checkout_template_id_hook', 'woocommerce_review_order_before_submit'),
3653 'default_value' => 'woocommerce_review_order_before_submit',
3654 'type' => 'select',
3655 'options' => array(
3656 'woocommerce_review_order_before_submit' => 'woocommerce_review_order_before_submit',
3657 'woocommerce_review_order_after_submit' => 'woocommerce_review_order_after_submit',
3658 ),
3659 ),
3660 array(
3661 'name' => __('Priority', 'e2pdf'),
3662 'key' => 'e2pdf_wc_checkout_template_id_priority',
3663 'value' => get_option('e2pdf_wc_checkout_template_id_priority', '10'),
3664 'default_value' => '10',
3665 'type' => 'text',
3666 'class' => 'e2pdf-numbers',
3667 'placeholder' => '0',
3668 ),
3669 ),
3670 );
3671
3672 /* Deprecate and move to Hooks */
3673 $options['woocommerce_group']['options'][] = array(
3674 'header' => __('Admin Order List', 'e2pdf'),
3675 'name' => __('Template', 'e2pdf'),
3676 'key' => 'e2pdf_wc_admin_order_actions_template_id',
3677 'value' => get_option('e2pdf_wc_admin_order_actions_template_id', '0'),
3678 'default_value' => '0',
3679 'type' => 'select',
3680 'options' => $order_templates,
3681 );
3682 $options['woocommerce_group']['options'][] = array(
3683 'name' => __('Hook', 'e2pdf'),
3684 'key' => 'e2pdf_wc_admin_order_actions_template_id_hook',
3685 'value' => get_option('e2pdf_wc_admin_order_actions_template_id_hook', 'woocommerce_admin_order_actions_end'),
3686 'default_value' => 'woocommerce_admin_order_actions_end',
3687 'type' => 'select',
3688 'options' => array(
3689 'woocommerce_admin_order_actions_start' => 'woocommerce_admin_order_actions_start',
3690 'woocommerce_admin_order_actions_end' => 'woocommerce_admin_order_actions_end',
3691 ),
3692 );
3693 $options['woocommerce_group']['options'][] = array(
3694 'name' => __('Order Status', 'e2pdf'),
3695 'key' => 'e2pdf_wc_admin_order_actions_template_id_status',
3696 'type' => 'checkbox_list',
3697 'options' => $this->get_status_options('e2pdf_wc_admin_order_actions_template_id'),
3698 );
3699 $options['woocommerce_group']['options'][] = array(
3700 'name' => __('Priority', 'e2pdf'),
3701 'key' => 'e2pdf_wc_admin_order_actions_template_id_priority',
3702 'value' => get_option('e2pdf_wc_admin_order_actions_template_id_priority', '10'),
3703 'default_value' => '10',
3704 'type' => 'text',
3705 'class' => 'e2pdf-numbers',
3706 'placeholder' => '0',
3707 );
3708
3709 $options['woocommerce_group']['options'][] = array(
3710 'header' => __('Admin Order Details', 'e2pdf'),
3711 'name' => __('Template', 'e2pdf'),
3712 'key' => 'e2pdf_wc_admin_order_details_template_id',
3713 'value' => get_option('e2pdf_wc_admin_order_details_template_id', '0'),
3714 'default_value' => '0',
3715 'type' => 'select',
3716 'options' => $order_templates,
3717 );
3718 $options['woocommerce_group']['options'][] = array(
3719 'name' => __('Order Status', 'e2pdf'),
3720 'key' => 'e2pdf_wc_admin_order_details_template_id_status',
3721 'type' => 'checkbox_list',
3722 'options' => $this->get_status_options('e2pdf_wc_admin_order_details_template_id'),
3723 );
3724
3725 return $options;
3726 }
3727
3728 public function get_status_options($key) {
3729 $statuses = get_option($key . '_status', array('any'));
3730 $order_statuses = array();
3731 if (function_exists('wc_get_order_statuses')) {
3732 $order_statuses = wc_get_order_statuses();
3733 }
3734 $status_options = array();
3735 foreach ($order_statuses as $order_status_key => $order_status) {
3736 $status_options[] = array(
3737 'name' => $order_status,
3738 'key' => $key . '_status[]',
3739 'value' => is_array($statuses) && in_array($order_status_key, $statuses, false) ? $order_status_key : '',
3740 'checkbox_value' => $order_status_key,
3741 'placeholder' => $order_status,
3742 'type' => 'checkbox',
3743 'default_value' => '',
3744 );
3745 }
3746
3747 $status_options[] = array(
3748 'name' => 'Any',
3749 'key' => $key . '_status[]',
3750 'value' => is_array($statuses) && in_array('any', $statuses, false) ? 'any' : '',
3751 'checkbox_value' => 'any',
3752 'placeholder' => __('Any', 'e2pdf'),
3753 'type' => 'checkbox',
3754 'default_value' => '',
3755 );
3756
3757 return $status_options;
3758 }
3759
3760 public function hook_woocommerce_order_edit() {
3761 $hooks = $this->helper->load('hooks')->get('woocommerce', 'hook_woocommerce_order_edit', 'shop_order');
3762 if (!empty($hooks)) {
3763 add_meta_box(
3764 'e2pdf',
3765 apply_filters('e2pdf_hook_section_title', __('E2Pdf Actions', 'e2pdf'), 'hook_woocommerce_order_edit'),
3766 array($this, 'hook_woocommerce_order_edit_callback'),
3767 'shop_order',
3768 'side',
3769 'default',
3770 array('hooks' => $hooks)
3771 );
3772 }
3773 }
3774
3775 public function hook_woocommerce_order_edit_callback($post, $metabox) {
3776 foreach ($metabox['args']['hooks'] as $hook) {
3777 if ($this->helper->load('hooks')->process_hook(
3778 $hook,
3779 [
3780 'dataset' => $post->ID,
3781 ],
3782 'hook_woocommerce_order_edit'
3783 )
3784 ) {
3785 $action = apply_filters(
3786 'e2pdf_hook_action_button',
3787 array(
3788 'html' => '<p><a class="e2pdf-download-hook" target="_blank" title="%2$s" href="%1$s"><span class="dashicons dashicons-pdf"></span> %2$s</a></p>',
3789 'url' => $this->helper->get_url(
3790 array(
3791 'page' => 'e2pdf',
3792 'action' => 'export',
3793 'id' => $hook,
3794 'dataset' => $post->ID,
3795 ), 'admin.php?'
3796 ),
3797 'title' => 'PDF #' . $hook,
3798 ), 'hook_woocommerce_order_edit', $hook, $post->ID
3799 );
3800 if (!empty($action)) {
3801 echo sprintf(
3802 $action['html'], $action['url'], $action['title']
3803 );
3804 }
3805 }
3806 }
3807 }
3808
3809 public function hook_woocommerce_subscription_edit() {
3810 $hooks = $this->helper->load('hooks')->get('woocommerce', 'hook_woocommerce_subscription_edit', 'shop_subscription');
3811 if (!empty($hooks)) {
3812 add_meta_box(
3813 'e2pdf',
3814 apply_filters('e2pdf_hook_section_title', __('E2Pdf Actions', 'e2pdf'), 'hook_woocommerce_subscription_edit'),
3815 array($this, 'hook_woocommerce_subscription_edit_callback'),
3816 'shop_subscription',
3817 'side',
3818 'default',
3819 array('hooks' => $hooks)
3820 );
3821 }
3822 }
3823
3824 public function hook_woocommerce_subscription_edit_callback($post, $metabox) {
3825 foreach ($metabox['args']['hooks'] as $hook) {
3826 if ($this->helper->load('hooks')->process_hook(
3827 $hook,
3828 [
3829 'dataset' => $post->ID,
3830 ],
3831 'hook_woocommerce_subscription_edit'
3832 )
3833 ) {
3834 $action = apply_filters(
3835 'e2pdf_hook_action_button',
3836 array(
3837 'html' => '<p><a class="e2pdf-download-hook" target="_blank" title="%2$s" href="%1$s"><span class="dashicons dashicons-pdf"></span> %2$s</a></p>',
3838 'url' => $this->helper->get_url(
3839 array(
3840 'page' => 'e2pdf',
3841 'action' => 'export',
3842 'id' => $hook,
3843 'dataset' => $post->ID,
3844 ), 'admin.php?'
3845 ),
3846 'title' => 'PDF #' . $hook,
3847 ), 'hook_woocommerce_subscription_edit', $hook, $post->ID
3848 );
3849 if (!empty($action)) {
3850 echo sprintf(
3851 $action['html'], $action['url'], $action['title']
3852 );
3853 }
3854 }
3855 }
3856 }
3857
3858 public function hook_woocommerce_order_row_actions($order) {
3859 if (!empty($order->id)) {
3860 $hooks = $this->helper->load('hooks')->get('woocommerce', 'hook_woocommerce_order_row_actions', 'shop_order');
3861 foreach ($hooks as $hook) {
3862 if ($this->helper->load('hooks')->process_hook(
3863 $hook,
3864 [
3865 'dataset' => $order->id,
3866 ],
3867 'hook_woocommerce_order_row_actions'
3868 )
3869 ) {
3870 $action = apply_filters(
3871 'e2pdf_hook_action_button',
3872 array(
3873 'html' => '<a class="button e2pdf-download-hook e2pdf-download-hook-icon-button" target="_blank" title="%2$s" href="%1$s">%2$s</a> ',
3874 'url' => $this->helper->get_url(
3875 array(
3876 'page' => 'e2pdf',
3877 'action' => 'export',
3878 'id' => $hook,
3879 'dataset' => $order->id,
3880 ), 'admin.php?'
3881 ),
3882 'title' => 'PDF #' . $hook,
3883 ), 'hook_woocommerce_order_row_actions', $hook, $order->id
3884 );
3885 if (!empty($action)) {
3886 echo sprintf(
3887 $action['html'], $action['url'], $action['title']
3888 );
3889 }
3890 }
3891 }
3892 }
3893 }
3894
3895 public function hook_woocommerce_order_row_column($columns) {
3896 $hooks = $this->helper->load('hooks')->get('woocommerce', 'hook_woocommerce_order_row_column', 'shop_order');
3897 if (!empty($hooks)) {
3898 $columns['e2pdf_hook_woocommerce_order_row_column'] = apply_filters('e2pdf_hook_section_title', __('E2Pdf Actions', 'e2pdf'), 'hook_woocommerce_order_row_column');
3899 add_action('manage_shop_order_posts_custom_column', array($this, 'hook_woocommerce_order_row_column_callback'), 10, 2);
3900 }
3901 return $columns;
3902 }
3903
3904 public function hook_woocommerce_order_row_column_callback($column, $post_id) {
3905 if ($column == 'e2pdf_hook_woocommerce_order_row_column') {
3906 $hooks = $this->helper->load('hooks')->get('woocommerce', 'hook_woocommerce_order_row_column', 'shop_order');
3907 foreach ($hooks as $hook) {
3908 if ($this->helper->load('hooks')->process_hook(
3909 $hook,
3910 [
3911 'dataset' => $post_id,
3912 ],
3913 'hook_woocommerce_order_row_column'
3914 )
3915 ) {
3916 $action = apply_filters(
3917 'e2pdf_hook_action_button',
3918 array(
3919 'html' => '<a class="button e2pdf-download-hook e2pdf-download-hook-icon-button" target="_blank" title="%2$s" href="%1$s">%2$s</a> ',
3920 'url' => $this->helper->get_url(
3921 array(
3922 'page' => 'e2pdf',
3923 'action' => 'export',
3924 'id' => $hook,
3925 'dataset' => $post_id,
3926 ), 'admin.php?'
3927 ),
3928 'title' => 'PDF #' . $hook,
3929 ), 'hook_woocommerce_order_row_column', $hook, $post_id
3930 );
3931 if (!empty($action)) {
3932 echo sprintf(
3933 $action['html'], $action['url'], $action['title']
3934 );
3935 }
3936 }
3937 }
3938 }
3939 }
3940
3941 public function hook_woocommerce_subscription_row_column($columns) {
3942 $hooks = $this->helper->load('hooks')->get('woocommerce', 'hook_woocommerce_subscription_row_column', 'shop_subscription');
3943 if (!empty($hooks)) {
3944 $columns['e2pdf_hook_woocommerce_subscription_row_column'] = apply_filters('e2pdf_hook_section_title', __('E2Pdf Actions', 'e2pdf'), 'hook_woocommerce_subscription_row_column');
3945 add_action('manage_shop_subscription_posts_custom_column', array($this, 'hook_woocommerce_subscription_row_column_callback'), 10, 2);
3946 }
3947 return $columns;
3948 }
3949
3950 public function hook_woocommerce_subscription_row_column_callback($column, $post_id) {
3951 if ($column == 'e2pdf_hook_woocommerce_subscription_row_column') {
3952 $hooks = $this->helper->load('hooks')->get('woocommerce', 'hook_woocommerce_subscription_row_column', 'shop_subscription');
3953 foreach ($hooks as $hook) {
3954 if ($this->helper->load('hooks')->process_hook(
3955 $hook,
3956 [
3957 'dataset' => $post_id,
3958 ],
3959 'hook_woocommerce_subscription_row_column'
3960 )
3961 ) {
3962 $action = apply_filters(
3963 'e2pdf_hook_action_button',
3964 array(
3965 'html' => '<a class="button e2pdf-download-hook e2pdf-download-hook-icon-button" target="_blank" title="%2$s" href="%1$s">%2$s</a> ',
3966 'url' => $this->helper->get_url(
3967 array(
3968 'page' => 'e2pdf',
3969 'action' => 'export',
3970 'id' => $hook,
3971 'dataset' => $post_id,
3972 ), 'admin.php?'
3973 ),
3974 'title' => 'PDF #' . $hook,
3975 ), 'hook_woocommerce_subscription_row_column', $hook, $post_id
3976 );
3977 if (!empty($action)) {
3978 echo sprintf(
3979 $action['html'], $action['url'], $action['title']
3980 );
3981 }
3982 }
3983 }
3984 }
3985 }
3986
3987 public function hook_woocommerce_my_account_my_orders_actions($actions, $order) {
3988 $hooks = $this->helper->load('hooks')->get('woocommerce', 'hook_woocommerce_my_account_my_orders_actions', 'shop_order');
3989 foreach ($hooks as $hook) {
3990 if ($this->helper->load('hooks')->process_hook(
3991 $hook,
3992 [
3993 'dataset' => $order->get_id(),
3994 ],
3995 'hook_woocommerce_my_account_my_orders_actions'
3996 )
3997 ) {
3998 $actions['e2pdf_' . $hook] = array(
3999 'url' => do_shortcode('[e2pdf-download id="' . $hook . '" dataset="' . $order->get_id() . '" noactions="true" output="url"]'),
4000 'name' => apply_filters('e2pdf_wc_my_account_my_orders_actions_invoice_title', do_shortcode('[e2pdf-download id="' . $hook . '" dataset="' . $order->get_id() . '" noactions="true" output="button_title"]')),
4001 );
4002 }
4003 }
4004 return apply_filters('e2pdf_wc_filter_woocommerce_my_account_my_orders_actions', $actions, $order);
4005 }
4006
4007 public function hook_wcs_view_subscription_actions($actions, $order) {
4008 $hooks = $this->helper->load('hooks')->get('woocommerce', 'hook_wcs_view_subscription_actions', 'shop_subscription');
4009 foreach ($hooks as $hook) {
4010 if ($this->helper->load('hooks')->process_hook(
4011 $hook,
4012 [
4013 'dataset' => $order->get_id(),
4014 ],
4015 'hook_wcs_view_subscription_actions'
4016 )
4017 ) {
4018 $actions['e2pdf_' . $hook] = array(
4019 'url' => do_shortcode('[e2pdf-download id="' . $hook . '" dataset="' . $order->get_id() . '" noactions="true" output="url"]'),
4020 'name' => apply_filters('e2pdf_wc_wcs_view_subscription_actions_actions_title', do_shortcode('[e2pdf-download id="' . $hook . '" dataset="' . $order->get_id() . '" noactions="true" output="button_title"]')),
4021 );
4022 }
4023 }
4024 return apply_filters('e2pdf_wc_filter_wcs_view_subscription_actions', $actions, $order);
4025 }
4026
4027 public function hook_woocommerce_order_details($order) {
4028 $hooks = $this->helper->load('hooks')->get('woocommerce', 'hook_' . current_action(), 'shop_order');
4029 foreach ($hooks as $hook) {
4030 if ($this->helper->load('hooks')->process_hook(
4031 $hook,
4032 [
4033 'dataset' => $order->get_id(),
4034 ],
4035 'hook_' . current_action()
4036 )
4037 ) {
4038 echo do_shortcode('[e2pdf-download id="' . $hook . '" dataset="' . $order->get_id() . '" noactions="true" class="button e2pdf-wc-download-button e2pdf-wc-download-order-details-button"]');
4039 }
4040 }
4041 }
4042
4043 public function hook_woocommerce_subscription_details($order) {
4044 $hooks = $this->helper->load('hooks')->get('woocommerce', 'hook_' . current_action(), 'shop_subscription');
4045
4046 if (!empty($hooks)) {
4047 echo '<tr><td>' . apply_filters('e2pdf_hook_section_title', __('E2Pdf Actions', 'e2pdf'), 'hook_' . current_action()) . '</td><td>';
4048 }
4049
4050 foreach ($hooks as $hook) {
4051 if ($this->helper->load('hooks')->process_hook(
4052 $hook,
4053 [
4054 'dataset' => $order->get_id(),
4055 ],
4056 'hook_' . current_action()
4057 )
4058 ) {
4059 echo do_shortcode('[e2pdf-download id="' . $hook . '" dataset="' . $order->get_id() . '" noactions="true" class="button e2pdf-wc-download-button e2pdf-wc-download-subscription-details-button"]');
4060 }
4061 }
4062
4063 if (!empty($hooks)) {
4064 echo '</td></tr>';
4065 }
4066 }
4067
4068 public function hook_woocommerce_proceed_to_checkout() {
4069 if (!is_cart() || WC()->cart->is_empty()) {
4070 return;
4071 }
4072 $hooks = $this->helper->load('hooks')->get('woocommerce', 'hook_woocommerce_proceed_to_checkout', 'cart');
4073 foreach ($hooks as $hook) {
4074 if ($this->helper->load('hooks')->process_hook(
4075 $hook,
4076 [
4077 'dataset' => wc_get_page_id('cart'),
4078 ],
4079 'hook_woocommerce_proceed_to_checkout'
4080 )
4081 ) {
4082 echo do_shortcode('[e2pdf-download id="' . $hook . '" dataset="' . wc_get_page_id('cart') . '" noactions="true" class="button e2pdf-wc-download-button e2pdf-wc-download-cart-button"]');
4083 }
4084 }
4085 }
4086
4087 public function hook_woocommerce_review_order() {
4088 if (!is_checkout() || WC()->cart->is_empty()) {
4089 return;
4090 }
4091 $hooks = $this->helper->load('hooks')->get('woocommerce', 'hook_' . current_action(), 'cart');
4092 foreach ($hooks as $hook) {
4093 if (
4094 $this->helper->load('hooks')->process_hook(
4095 $hook,
4096 [
4097 'dataset' => wc_get_page_id('cart'),
4098 ],
4099 'hook_' . current_action()
4100 )
4101 ) {
4102 echo do_shortcode('[e2pdf-download id="' . $hook . '" dataset="' . wc_get_page_id('cart') . '" noactions="true" class="button e2pdf-wc-download-button e2pdf-wc-download-checkout-button"]');
4103 }
4104 }
4105 }
4106 }
4107