PluginProbe ʕ •ᴥ•ʔ
Event Tickets with Ticket Scanner / 2.6.0
Event Tickets with Ticket Scanner v2.6.0
3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.4 trunk 2.6.0 2.7.0 2.7.1 2.7.10 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.10 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.0 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2 3.0.3
event-tickets-with-ticket-scanner / woocommerce-hooks.php
event-tickets-with-ticket-scanner Last commit date
3rd 1 year ago css 1 year ago img 1 year ago languages 1 year ago ticket 1 year ago vendors 1 year ago SASO_EVENTTICKETS.php 1 year ago backend.js 1 year ago changelog.txt 1 year ago db.php 1 year ago index.php 1 year ago init_file.php 1 year ago order_details.js 1 year ago readme.txt 1 year ago saso-eventtickets-validator.js 1 year ago sasoEventtickets_AdminSettings.php 1 year ago sasoEventtickets_Authtoken.php 1 year ago sasoEventtickets_Base.php 1 year ago sasoEventtickets_Core.php 1 year ago sasoEventtickets_Frontend.php 1 year ago sasoEventtickets_Options.php 1 year ago sasoEventtickets_PDF.php 1 year ago sasoEventtickets_Ticket.php 1 year ago sasoEventtickets_TicketBadge.php 1 year ago sasoEventtickets_TicketDesigner.php 1 year ago sasoEventtickets_TicketQR.php 1 year ago ticket_events.js 1 year ago ticket_scanner.js 1 year ago validator.js 1 year ago wc_backend.js 1 year ago wc_frontend.js 1 year ago woocommerce-hooks.php 1 year ago
woocommerce-hooks.php
2909 lines
1 <?php
2 include_once(plugin_dir_path(__FILE__)."init_file.php");
3 if (!defined('SASO_EVENTTICKETS_PLUGIN_MIN_WC_VER')) define( 'SASO_EVENTTICKETS_PLUGIN_MIN_WC_VER', '4.0' );
4
5 use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
6
7 class sasoEventtickets_WC {
8 private $MAIN;
9 private $meta_key_codelist_restriction = 'saso_eventtickets_list_sale_restriction';
10 private $meta_key_codelist_restriction_order_item = '_saso_eventticket_list_sale_restriction';
11 private $_containsProductsWithRestrictions = null;
12 private $js_inputType = 'eventcoderestriction';
13
14 private $_isTicket;
15 private $_product;
16
17 private $refund_parent_id; // order_id
18
19 private $_attachments = [];
20
21 public function __construct($MAIN) {
22 $this->MAIN = $MAIN;
23 }
24
25 public function executeJSON($a, $data=[], $just_ret=false) {
26 $ret = "";
27 $justJSON = false;
28 try {
29 switch (trim($a)) {
30 case "downloadFlyer":
31 $ret = $this->downloadFlyer($data);
32 break;
33 case "downloadICSFile":
34 $ret = $this->downloadICSFile($data);
35 break;
36 case "downloadTicketInfosOfProduct":
37 $ret = $this->downloadTicketInfosOfProduct($data);
38 break;
39 case "downloadAllTicketsAsOnePDF":
40 $ret = $this->downloadAllTicketsAsOnePDF($data);
41 break;
42 case "removeAllTicketsFromOrder":
43 $ret = $this->removeAllTicketsFromOrder($data);
44 break;
45 case "removeAllNonTicketsFromOrder":
46 $ret = $this->removeAllNonTicketsFromOrder($data);
47 break;
48 default:
49 throw new Exception("#6000 ".sprintf(/* translators: %s: name of called function */esc_html__('function "%s" in wc backend not implemented', 'event-tickets-with-ticket-scanner'), $a));
50 }
51 } catch(Exception $e) {
52 $this->MAIN->getAdmin()->logErrorToDB($e);
53 if ($just_ret) throw $e;
54 return wp_send_json_error ($e->getMessage());
55 }
56 if ($just_ret) return $ret;
57 if ($justJSON) return wp_send_json($ret);
58 else return wp_send_json_success( $ret );
59 }
60
61 private function getPrefix() {
62 return $this->MAIN->getPrefix();
63 }
64 public function setProduct($product) {
65 $this->_product = $product;
66 }
67 private function getProduct() {
68 if ($this->_product == null) {
69 $this->setProduct(wc_get_product());
70 }
71 return $this->_product;
72 }
73 private function isTicket() {
74 if ($this->_isTicket == null) {
75 $product = $this->getProduct();
76 $this->_isTicket = $this->isTicketByProductId($product->get_id());
77 }
78 return $this->_isTicket;
79 }
80 public function isTicketByProductId($product_id) {
81 $product_id = intval($product_id);
82 if ($product_id < 1) return false;
83 return get_post_meta($product_id, 'saso_eventtickets_is_ticket', true) == "yes";
84 }
85
86 function wc_get_lists() {
87 $lists = $this->getAdmin()->getLists();
88 $dropdown_list = array(''=>esc_attr__('Deactivate auto-generating ticket', 'event-tickets-with-ticket-scanner'));
89 foreach ($lists as $key => $list) {
90 $dropdown_list[$list['id']] = $list['name'];
91 }
92
93 return $dropdown_list;
94 }
95
96 function wc_get_lists_sales_restriction() {
97 $lists = $this->getAdmin()->getLists();
98 $dropdown_list = array(''=>esc_attr__('No restriction applied', 'event-tickets-with-ticket-scanner'), '0'=>esc_attr__('Accept any existing code without limitation to a code list', 'event-tickets-with-ticket-scanner'));
99 foreach ($lists as $key => $list) {
100 $dropdown_list[$list['id']] = $list['name'];
101 }
102
103 return $dropdown_list;
104 }
105
106 public function woocommerce_product_after_variable_attributes($loop, $variation_data, $variation) {
107 echo '<div class="form-row form-row-full form-field">';
108 woocommerce_wp_checkbox(
109 array(
110 'id' => '_saso_eventtickets_is_not_ticket[' . $loop . ']',
111 'label' => __( 'This variation is NOT a ticket product', 'event-tickets-with-ticket-scanner' ),
112 'desc_tip' => 'true',
113 'description' => __( 'This allows you to exclude a variation to be a ticket', 'event-tickets-with-ticket-scanner' ),
114 'value' => get_post_meta( $variation->ID, '_saso_eventtickets_is_not_ticket', true )
115 )
116 );
117 echo '<div style="border-left: 5px solid #b225cb;padding-left:30px;margin-left:16px;">';
118 woocommerce_wp_text_input([
119 'id' => 'saso_eventtickets_ticket_start_date[' . $loop . ']',
120 'value' => get_post_meta( $variation->ID, 'saso_eventtickets_ticket_start_date', true ),
121 'label' => __('Start date event', 'event-tickets-with-ticket-scanner'),
122 'type' => 'date',
123 'custom_attributes' => ['data-type'=>'date'],
124 'description' => __('Set this to have this printed on the ticket and prevent too early redeemed tickets. Tickets can be redeemed from that day on.', 'event-tickets-with-ticket-scanner'),
125 'desc_tip' => true
126 ]);
127 woocommerce_wp_text_input([
128 'id' => 'saso_eventtickets_ticket_start_time[' . $loop . ']',
129 'value' => get_post_meta( $variation->ID, 'saso_eventtickets_ticket_start_time', true ),
130 'label' => __('Start time', 'event-tickets-with-ticket-scanner'),
131 'type' => 'time',
132 'description' => __('Set this to have this printed on the ticket.', 'event-tickets-with-ticket-scanner'),
133 'desc_tip' => true
134 ]);
135 woocommerce_wp_text_input([
136 'id' => 'saso_eventtickets_ticket_end_date[' . $loop . ']',
137 'value' => get_post_meta( $variation->ID, 'saso_eventtickets_ticket_end_date', true ),
138 'label' => __('End date event', 'event-tickets-with-ticket-scanner'),
139 'type' => 'date',
140 'custom_attributes' => ['data-type'=>'date'],
141 'description' => __('Set this to have this printed on the ticket and prevent later the ticket to be still valid. Tickets cannot be redeemed after that day.', 'event-tickets-with-ticket-scanner'),
142 'desc_tip' => true
143 ]);
144 woocommerce_wp_text_input([
145 'id' => 'saso_eventtickets_ticket_end_time[' . $loop . ']',
146 'value' => get_post_meta( $variation->ID, 'saso_eventtickets_ticket_end_time', true ),
147 'label' => __('End time', 'event-tickets-with-ticket-scanner'),
148 'type' => 'time',
149 'description' => __('Set this to have this printed on the ticket.', 'event-tickets-with-ticket-scanner'),
150 'desc_tip' => true
151 ]);
152 echo '</div>';
153 echo '</div>';
154
155 echo '<div class="options_group">';
156 $saso_eventtickets_ticket_amount_per_item = intval(get_post_meta( $variation->ID, 'saso_eventtickets_ticket_amount_per_item', true ));
157 if ($saso_eventtickets_ticket_amount_per_item < 1) $saso_eventtickets_ticket_amount_per_item = 1;
158 woocommerce_wp_text_input([
159 'id' => 'saso_eventtickets_ticket_amount_per_item[' . $loop . ']',
160 'value' => $saso_eventtickets_ticket_amount_per_item,
161 'label' => __('Amount of ticket numbers per item sale', 'event-tickets-with-ticket-scanner'),
162 'type' => 'number',
163 'custom_attributes' => ['step'=>'1', 'min'=>'1'],
164 'description' => __('How many ticket number to assign if one product is sold?', 'event-tickets-with-ticket-scanner'),
165 'desc_tip' => true
166 ]);
167 echo '</div>';
168
169 if ($this->MAIN->isPremium() && method_exists($this->MAIN->getPremiumFunctions(), 'woocommerce_product_after_variable_attributes')) {
170 $this->MAIN->getPremiumFunctions()->woocommerce_product_after_variable_attributes($loop, $variation_data, $variation);
171 }
172 echo "<hr>";
173 }
174
175 public function woocommerce_save_product_variation($variation_id, $i) {
176 $R = SASO_EVENTTICKETS::getRequest();
177 // checkbox
178 $key = '_saso_eventtickets_is_not_ticket';
179 if( isset($R[$key]) && isset($R[$key][$i]) ) {
180 update_post_meta( $variation_id, $key, 'yes');
181 } else {
182 delete_post_meta( $variation_id, $key );
183 }
184 // text input fields
185 $keys = [
186 'saso_eventtickets_ticket_start_date',
187 'saso_eventtickets_ticket_start_time',
188 'saso_eventtickets_ticket_end_date',
189 'saso_eventtickets_ticket_end_time'];
190 foreach($keys as $key) {
191 if( isset($R[$key]) && isset($R[$key][$i]) ) {
192 update_post_meta( $variation_id, $key, sanitize_text_field($R[$key][$i]) );
193 } else {
194 delete_post_meta( $variation_id, $key );
195 }
196 }
197 // numbers
198 $key = 'saso_eventtickets_ticket_amount_per_item';
199 if( isset($R[$key]) && isset($R[$key][$i]) ) {
200 $value = intval($R[$key][$i]);
201 if ($value < 1) $value = 1;
202 update_post_meta( $variation_id, $key, $value );
203 } else {
204 delete_post_meta( $variation_id, $key );
205 }
206
207 if ($this->MAIN->isPremium() && method_exists($this->MAIN->getPremiumFunctions(), 'woocommerce_save_product_variation')) {
208 $this->MAIN->getPremiumFunctions()->woocommerce_save_product_variation($variation_id, $i);
209 }
210 }
211
212 public function woocommerce_product_data_tabs($tabs) {
213 //unset( $tabs['inventory'] );
214 $tabs['saso_eventtickets_code_woo'] = array(
215 'label' => _x('Event Tickets', 'label', 'event-tickets-with-ticket-scanner'),
216 'title' => _x('Event Tickets', 'title', 'event-tickets-with-ticket-scanner'),
217 'target' => 'saso_eventtickets_wc_product_data',
218 //'class' => ['show_if_simple', 'show_if_variable', 'show_if_external']
219 'class'=>['hide_if_grouped']
220 );
221 return $tabs;
222 }
223
224 /**
225 * product tab content
226 */
227 public function woocommerce_product_data_panels() {
228 $product = wc_get_product(get_the_ID());
229 //$is_variable = $product->get_type() == "variable" ? true : false;
230 $is_variation = $product->get_type() == "variation" ? true : false;
231 $prem_JS_file = "";
232 if ($this->MAIN->isPremium() && method_exists($this->MAIN->getPremiumFunctions(), 'getJSBackendFile')) {
233 $prem_JS_file = $this->MAIN->getPremiumFunctions()->getJSBackendFile();
234 }
235
236 wp_enqueue_style("wp-jquery-ui-dialog");
237
238 wp_register_script(
239 'SasoEventticketsValidator_WC_backend',
240 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'wc_backend.js?_v='.$this->MAIN->getPluginVersion(),
241 array( 'jquery', 'jquery-blockui', 'wp-i18n'),
242 (current_user_can("administrator") ? current_time("timestamp") : $this->MAIN->getPluginVersion()),
243 true );
244 wp_localize_script(
245 'SasoEventticketsValidator_WC_backend',
246 'Ajax_sasoEventtickets_wc', // name der js variable
247 [
248 'ajaxurl' => admin_url( 'admin-ajax.php' ),
249 '_plugin_home_url' =>plugins_url( "",__FILE__ ),
250 'prefix'=>$this->MAIN->getPrefix(),
251 'nonce' => wp_create_nonce( $this->MAIN->_js_nonce ),
252 'action' => $this->MAIN->getPrefix().'_executeWCBackend',
253 'product_id'=>isset($_GET['post']) ? intval($_GET['post']) : 0,
254 'order_id'=>0,
255 'scope'=>'product',
256 '_doNotInit'=>true,
257 '_max'=>$this->MAIN->getBase()->getMaxValues(),
258 '_isPremium'=>$this->MAIN->isPremium(),
259 '_isUserLoggedin'=>is_user_logged_in(),
260 '_backendJS'=>trailingslashit( plugin_dir_url( __FILE__ ) ) . 'backend.js?_v='.$this->MAIN->getPluginVersion(),
261 '_premJS'=>$prem_JS_file,
262 '_divAreaId'=>'saso_eventtickets_list_format_area',
263 'formatterInputFieldDataId'=>'saso_eventtickets_list_formatter_values'
264 ] // werte in der js variable
265 );
266 wp_enqueue_script('SasoEventticketsValidator_WC_backend');
267 wp_set_script_translations('SasoEventticketsValidator_WC_backend', 'event-tickets-with-ticket-scanner', __DIR__.'/languages');
268
269 $js_url = "jquery.qrcode.min.js?_v=".$this->MAIN->getPluginVersion();
270 wp_enqueue_script(
271 'ajax_script2',
272 plugins_url( "3rd/".$js_url,__FILE__ ),
273 array('jquery', 'jquery-ui-dialog')
274 );
275
276 wp_enqueue_style($this->MAIN->getPrefix()."_backendcss", plugins_url( "",__FILE__ ).'/css/styles_backend.css');
277
278 echo '<div id="saso_eventtickets_wc_product_data" class="panel woocommerce_options_panel hidden">';
279
280 if (!$this->MAIN->isPremium()) {
281 $mv = $this->MAIN->getMV();
282 echo '<p style="color:red;">'.sprintf(/* translators: %d: amount of maximum ticket that can be created */__('With the free basic plugin, you can only <b>create up to %d tickets!</b><br>Make sure your are not selling more tickets :)', 'event-tickets-with-ticket-scanner'), intval($mv['codes_total'])).'<br>'.sprintf(/* translators: 1: start of a-tag 2: end of a-tag */__('Here you can purchase the %1$spremium plugin%2$s for unlimited tickets.', 'event-tickets-with-ticket-scanner'), '<a target="_blank" href="https://vollstart.com/event-tickets-with-ticket-scanner/">', '</a>').'</p>';
283 }
284
285 $is_ticket_activated = get_post_meta( get_the_ID(), 'saso_eventtickets_is_ticket', true );
286 echo '<div class="options_group">';
287 woocommerce_wp_checkbox([
288 'id' => 'saso_eventtickets_is_ticket',
289 'value' => $is_ticket_activated,
290 'label' => __('Is a ticket sales', 'event-tickets-with-ticket-scanner'),
291 'description' => __('Activate this, to generate a ticket number', 'event-tickets-with-ticket-scanner')
292 ]);
293 echo "<p><b>Important:</b> You need to choose a list below, to activate the ticket sale for this product.</p>";
294 $ticket_lists = $this->wc_get_lists();
295 if (count($ticket_lists) == 1) { // only deactivation option is available
296 echo "<p><b>".esc_html__('You have no lists created!', 'event-tickets-with-ticket-scanner')."</b><br>".esc_html__('You need to create a list first within the event tickets admin area, to choose a list from.', 'event-tickets-with-ticket-scanner')."</b></p>";
297 }
298 $ticket_list_id_choosen = get_post_meta( get_the_ID(), 'saso_eventtickets_list', true );
299 if (empty($ticket_list_id_choosen) && $is_ticket_activated != "yes" && count($ticket_lists) > 1) {
300 $ticket_list_id_choosen = "1";
301 }
302 woocommerce_wp_select( array(
303 'id' => 'saso_eventtickets_list',
304 'value' => $ticket_list_id_choosen,
305 'label' => __('List', 'event-tickets-with-ticket-scanner'),
306 'description' => __('Choose a list to activate auto-generating ticket numbers/codes for each sold item', 'event-tickets-with-ticket-scanner'),
307 'desc_tip' => true,
308 'options' => $ticket_lists
309 ) );
310 echo '</div>';
311
312 echo '<div class="options_group">';
313 woocommerce_wp_text_input([
314 'id' => 'saso_eventtickets_event_location',
315 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_event_location', true ),
316 'label' => wp_kses_post($this->getOptions()->getOptionValue("wcTicketTransLocation")),
317 'type' => 'text',
318 'description' => __('This will be also in the cal entry file.', 'event-tickets-with-ticket-scanner'),
319 'desc_tip' => true
320 ]);
321 woocommerce_wp_text_input([
322 'id' => 'saso_eventtickets_ticket_start_date',
323 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_ticket_start_date', true ),
324 'label' => __('Start date event', 'event-tickets-with-ticket-scanner'),
325 'type' => 'date',
326 'custom_attributes' => ['data-type'=>'date'],
327 'description' => __('Set this to have this printed on the ticket and prevent too early redeemed tickets. Tickets can be redeemed from that day on.', 'event-tickets-with-ticket-scanner'),
328 'desc_tip' => true
329 ]);
330 woocommerce_wp_text_input([
331 'id' => 'saso_eventtickets_ticket_start_time',
332 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_ticket_start_time', true ),
333 'label' => __('Start time', 'event-tickets-with-ticket-scanner'),
334 'type' => 'time',
335 'description' => __('Set this to have this printed on the ticket.', 'event-tickets-with-ticket-scanner'),
336 'desc_tip' => true
337 ]);
338 woocommerce_wp_text_input([
339 'id' => 'saso_eventtickets_ticket_end_date',
340 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_ticket_end_date', true ),
341 'label' => __('End date event', 'event-tickets-with-ticket-scanner'),
342 'type' => 'date',
343 'custom_attributes' => ['data-type'=>'date'],
344 'description' => __('Set this to have this printed on the ticket and prevent later the ticket to be still valid. Tickets cannot be redeemed after that day.', 'event-tickets-with-ticket-scanner'),
345 'desc_tip' => true
346 ]);
347 woocommerce_wp_text_input([
348 'id' => 'saso_eventtickets_ticket_end_time',
349 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_ticket_end_time', true ),
350 'label' => __('End time', 'event-tickets-with-ticket-scanner'),
351 'type' => 'time',
352 'description' => __('Set this to have this printed on the ticket.', 'event-tickets-with-ticket-scanner'),
353 'desc_tip' => true
354 ]);
355 if (true || $is_variation) {
356 woocommerce_wp_checkbox([
357 'id' => 'saso_eventtickets_is_date_for_all_variants',
358 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_is_date_for_all_variants', true ),
359 'label' => __('Date is for all variants', 'event-tickets-with-ticket-scanner'),
360 'description' => __('Activate this, to have the entered date printed on all product variants. No effect on simple products.', 'event-tickets-with-ticket-scanner')
361 ]);
362 }
363 echo '</div>';
364
365 echo '<div class="options_group">';
366 // checkbox to activate the date choosnowser
367 // info, that only the time will be taken from the date settings. If no time is set then it will be treated like 0:00 - 23:59.
368 woocommerce_wp_checkbox([
369 'id' => 'saso_eventtickets_is_daychooser',
370 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_is_daychooser', true ),
371 'label' => __('Customer can choose the day', 'event-tickets-with-ticket-scanner'),
372 'description' => __('Activate this, to allow your customer to choose a date. If this option is active it will ignore the start and end date and use only the start and end time setting. If the start and end time is not set, then the entrance is allowed from 00:00 till 23:59.', 'event-tickets-with-ticket-scanner')
373 ]);
374 // checkboxes to exclude days of week
375 woocommerce_wp_select( array(
376 'id' => 'saso_eventtickets_daychooser_exclude_wdays',
377 'name' => 'saso_eventtickets_daychooser_exclude_wdays[]',
378 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_daychooser_exclude_wdays', true ),
379 'label' => __('Choose which days to exclude', 'event-tickets-with-ticket-scanner'),
380 'description' => __('To select more than one, hold down the CTRL key. The selected days cannot be choosen by your customer in date chooser.', 'event-tickets-with-ticket-scanner'),
381 'desc_tip' => true,
382 'class' => 'cb-admin-multiselect',
383 'options' => [
384 "1"=>__('Monday', 'event-tickets-with-ticket-scanner'),
385 "2"=>__('Tuesday', 'event-tickets-with-ticket-scanner'),
386 "3"=>__('Wednesday', 'event-tickets-with-ticket-scanner'),
387 "4"=>__('Thursday', 'event-tickets-with-ticket-scanner'),
388 "5"=>__('Friday', 'event-tickets-with-ticket-scanner'),
389 "6"=>__('Saturday', 'event-tickets-with-ticket-scanner'),
390 "0"=>__('Sunday', 'event-tickets-with-ticket-scanner')
391 ],
392 'custom_attributes' => array('multiple' => 'multiple')
393 ) );
394 // input field for offset first day to choose from in days
395 woocommerce_wp_text_input([
396 'id' => 'saso_eventtickets_daychooser_offset_start',
397 'value' => intval(get_post_meta( get_the_ID(), 'saso_eventtickets_daychooser_offset_start', true )),
398 'label' => __('Offset days for start date', 'event-tickets-with-ticket-scanner'),
399 'type' => 'number',
400 'custom_attributes' => ['step'=>'1', 'min'=>'0'],
401 'description' => __('This will set how many days to skip before you allow your customer to choose a date. 0 means starting from the same day, 1 means from tomorrow on and so on. If you set a start date, the the start date will be considered as a minimum starting date.', 'event-tickets-with-ticket-scanner'),
402 'desc_tip' => true
403 ]);
404 // input field for offset last day to choose from in days
405 woocommerce_wp_text_input([
406 'id' => 'saso_eventtickets_daychooser_offset_end',
407 'value' => intval(get_post_meta( get_the_ID(), 'saso_eventtickets_daychooser_offset_end', true )),
408 'label' => __('Offset days for end date', 'event-tickets-with-ticket-scanner'),
409 'type' => 'number',
410 'custom_attributes' => ['step'=>'1', 'min'=>'0'],
411 'description' => __('This will set how many days in the future do you allow your customer to choose a date. 0 unlimited into the future, 1 means until tomorrow on and so on. If a end date is set, then this option is ignored and the end date is used.', 'event-tickets-with-ticket-scanner'),
412 'desc_tip' => true
413 ]);
414 woocommerce_wp_text_input([
415 'id' => 'saso_eventtickets_request_daychooser_per_ticket_label',
416 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_request_daychooser_per_ticket_label', true ),
417 'label' => __('Label for the date picker', 'event-tickets-with-ticket-scanner'),
418 'description' => __('This is how your customer understand what value should be choosen.', 'event-tickets-with-ticket-scanner'),
419 'placeholder' => 'Please choose a day #{count}:',
420 'desc_tip' => true
421 ]);
422
423 echo '</div>';
424
425 echo '<div class="options_group">';
426 $_max_redeem_amount = get_post_meta( get_the_ID(), 'saso_eventtickets_ticket_max_redeem_amount', true );
427 if (empty($_max_redeem_amount) || $_max_redeem_amount == "0") {
428 $max_redeem_amount = 1;
429 } else {
430 $max_redeem_amount = intval($_max_redeem_amount);
431 if ($max_redeem_amount < 1) $max_redeem_amount = 1;
432 }
433 woocommerce_wp_text_input([
434 'id' => 'saso_eventtickets_ticket_max_redeem_amount',
435 'value' => $max_redeem_amount,
436 'label' => __('Max. redeem operations', 'event-tickets-with-ticket-scanner'),
437 'type' => 'number',
438 'custom_attributes' => ['step'=>'1', 'min'=>'0'],
439 'description' => __('How often do you allow to redeem the ticket? If you set it to 0, you can redeem the ticket unlimited.', 'event-tickets-with-ticket-scanner'),
440 'desc_tip' => true
441 ]);
442 woocommerce_wp_textarea_input([
443 'id' => 'saso_eventtickets_ticket_is_ticket_info',
444 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_ticket_is_ticket_info', true ),
445 'label' => __('Print this on the ticket', 'event-tickets-with-ticket-scanner'),
446 'description' => __('This optional information will be displayed on the ticket detail page.', 'event-tickets-with-ticket-scanner'),
447 'desc_tip' => true
448 ]);
449
450 /*
451 woocommerce_wp_checkbox( array(
452 'id' => 'saso_eventtickets_ticket_is_RTL',
453 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_ticket_is_RTL', true ),
454 'label' => __('Text is RTL', 'event-tickets-with-ticket-scanner'),
455 'description' => __('Activate this, to use language from right to left.', 'event-tickets-with-ticket-scanner')
456 ));
457 */
458 echo '</div>';
459
460 echo '<div class="options_group">';
461 $saso_eventtickets_ticket_amount_per_item = intval(get_post_meta( get_the_ID(), 'saso_eventtickets_ticket_amount_per_item', true ));
462 if ($saso_eventtickets_ticket_amount_per_item < 1) $saso_eventtickets_ticket_amount_per_item = 1;
463 woocommerce_wp_text_input([
464 'id' => 'saso_eventtickets_ticket_amount_per_item',
465 'value' => $saso_eventtickets_ticket_amount_per_item,
466 'label' => __('Amount of ticket numbers per item sale', 'event-tickets-with-ticket-scanner'),
467 'type' => 'number',
468 'custom_attributes' => ['step'=>'1', 'min'=>'1'],
469 'description' => __('How many ticket number to assign if one product is sold?', 'event-tickets-with-ticket-scanner'),
470 'desc_tip' => true
471 ]);
472 echo '</div>';
473
474 echo '<div class="options_group">';
475 woocommerce_wp_checkbox([
476 'id' => 'saso_eventtickets_request_name_per_ticket',
477 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_request_name_per_ticket', true ),
478 'label' => __('Request a value for each ticket', 'event-tickets-with-ticket-scanner'),
479 'description' => __('Activate this, so that your customer can add a value for each ticket. This could be the name or any other value, defined by you. This value will be printed on the ticket. The value is limited to max 140 letters.', 'event-tickets-with-ticket-scanner')
480 ]);
481 woocommerce_wp_text_input([
482 'id' => 'saso_eventtickets_request_name_per_ticket_label',
483 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_request_name_per_ticket_label', true ),
484 'label' => __('Label for the value', 'event-tickets-with-ticket-scanner'),
485 'description' => __('This is how your customer understand what value should be entered.', 'event-tickets-with-ticket-scanner'),
486 'placeholder' => 'Name for the ticket #{count}:',
487 'desc_tip' => true
488 ]);
489 woocommerce_wp_checkbox([
490 'id' => 'saso_eventtickets_request_name_per_ticket_mandatory',
491 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_request_name_per_ticket_mandatory', true ),
492 'label' => __('The value for each ticket is mandatory', 'event-tickets-with-ticket-scanner'),
493 'description' => __('Activate this, so that your customer has to enter a value.', 'event-tickets-with-ticket-scanner')
494 ]);
495
496 echo "<hr>";
497
498 woocommerce_wp_checkbox([
499 'id' => 'saso_eventtickets_request_value_per_ticket',
500 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_request_value_per_ticket', true ),
501 'label' => __('Request a value for each ticket from dropdown', 'event-tickets-with-ticket-scanner'),
502 'description' => __('Activate this, so that your customer can choose a value for each ticket.', 'event-tickets-with-ticket-scanner')
503 ]);
504 woocommerce_wp_textarea_input([
505 'id' => 'saso_eventtickets_request_value_per_ticket_label',
506 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_request_value_per_ticket_label', true ),
507 'label' => __('Label for the value', 'event-tickets-with-ticket-scanner'),
508 'description' => __('This is how your customer understand what value should be choosen.', 'event-tickets-with-ticket-scanner'),
509 'placeholder' => 'Please choose a value #{count}:',
510 'desc_tip' => true
511 ]);
512 woocommerce_wp_textarea_input([
513 'id' => 'saso_eventtickets_request_value_per_ticket_values',
514 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_request_value_per_ticket_values', true ),
515 'label' => __('Values for the dropdown', 'event-tickets-with-ticket-scanner'),
516 'description' => __('Enter per line a key value pair like key|value1. If only key is given per line, then the key will be also the value.', 'event-tickets-with-ticket-scanner'),
517 'placeholder' => "|Please choose\nkey1|value1\nkey2|value2\nvalue3",
518 'desc_tip' => true
519 ]);
520 woocommerce_wp_text_input([
521 'id' => 'saso_eventtickets_request_value_per_ticket_def',
522 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_request_value_per_ticket_def', true ),
523 'label' => __('Enter default key for the dropdown (optional)', 'event-tickets-with-ticket-scanner'),
524 'description' => __('If not empty, the system will add the value with this key as the default chosen value.', 'event-tickets-with-ticket-scanner'),
525 'placeholder' => 'key1',
526 'desc_tip' => true
527 ]);
528 woocommerce_wp_checkbox([
529 'id' => 'saso_eventtickets_request_value_per_ticket_mandatory',
530 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_request_value_per_ticket_mandatory', true ),
531 'label' => __('The value for each ticket is mandatory', 'event-tickets-with-ticket-scanner'),
532 'description' => __('Activate this, so that your customer has to choose a value.', 'event-tickets-with-ticket-scanner')
533 ]);
534 echo '</div>';
535
536 echo '<div class="options_group">';
537 woocommerce_wp_checkbox( array(
538 'id' => 'saso_eventtickets_list_formatter',
539 'label' => __('Use format settings', 'event-tickets-with-ticket-scanner'),
540 'description' => __('If active, then the format below will be used to generate ticket numbers during a purchase of this product.', 'event-tickets-with-ticket-scanner'),
541 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_list_formatter', true )
542 ) );
543 echo '<input data-id="saso_eventtickets_list_formatter_values" name="saso_eventtickets_list_formatter_values" type="hidden" value="'.esc_js(get_post_meta( get_the_ID(), 'saso_eventtickets_list_formatter_values', true )).'">';
544 echo '<div style="padding-top:10px;padding-left:10%;padding-right:20px;"><b>'.esc_html__('The ticket number format settings.', 'event-tickets-with-ticket-scanner').'</b><br><i>'.esc_html__('This will override an existing and active global "serial code formatter pattern for new sales" and also any format settings from the group.', 'event-tickets-with-ticket-scanner').'</i><div id="saso_eventtickets_list_format_area"></div></div>';
545 echo '</div>';
546
547 /*
548 echo '<div class="options_group">';
549 if (version_compare( WC_VERSION, SASO_EVENTTICKETS_PLUGIN_MIN_WC_VER, '<' )) {
550 echo '<div class="error"><p><strong>' . sprintf( esc_html__( 'For the Code List for sale restriction the plugin requires WooCommerce %1$s or greater to be installed and active. WooCommerce %2$s is not supported.', 'event-tickets-with-ticket-scanner' ), SASO_EVENTTICKETS_PLUGIN_MIN_WC_VER, WC_VERSION ) . '</strong></p></div>';
551 echo '<p><strong>' . sprintf( esc_html__( 'For the Code List for sale restriction the plugin requires WooCommerce %1$s or greater to be installed and active. WooCommerce %2$s is not supported.', 'event-tickets-with-ticket-scanner' ), SASO_EVENTTICKETS_PLUGIN_MIN_WC_VER, WC_VERSION ) . '</strong></p>';
552 } else {
553 woocommerce_wp_select( array(
554 'id' => 'saso_eventtickets_list_sale_restriction',
555 'value' => get_post_meta( get_the_ID(), 'saso_eventtickets_list_sale_restriction', true ),
556 'label' => 'Code List for sale restriction ',
557 'description' => 'Choose a code list to restrict the sale of this product to be done only with a working code from this list',
558 'desc_tip' => true,
559 'options' => $this->wc_get_lists_sales_restriction()
560 ) );
561 }
562 echo '</div>';
563 */
564
565 if ($this->MAIN->isPremium() && method_exists($this->MAIN->getPremiumFunctions(), 'saso_eventtickets_wc_product_panels')) {
566 $this->MAIN->getPremiumFunctions()->saso_eventtickets_wc_product_panels(get_the_ID());
567 }
568
569 echo '</div>';
570 }
571
572 public function woocommerce_process_product_meta( $id, $post ) {
573 $R = SASO_EVENTTICKETS::getRequest();
574
575 $key = 'saso_eventtickets_list';
576 if( isset($R[$key]) && !empty( $R[$key] ) ) {
577 update_post_meta( $id, $key, sanitize_text_field($R[$key]) );
578 } else {
579 delete_post_meta( $id, $key );
580 }
581
582 // damit nicht alte Eintragungen gelöscht werden - so kann der kunde upgrade machen und alles ist noch da
583 if (version_compare( WC_VERSION, SASO_EVENTTICKETS_PLUGIN_MIN_WC_VER, '>=' )) {
584 $key = 'saso_eventtickets_list_sale_restriction';
585 if( isset($R[$key]) && ($R[$key] == '0' || !empty( $R[$key] )) ) {
586 update_post_meta( $id, $key, sanitize_text_field($R[$key]) );
587 } else {
588 delete_post_meta( $id, $key );
589 }
590 }
591
592 $keys_checkbox = [
593 'saso_eventtickets_is_ticket',
594 'saso_eventtickets_is_date_for_all_variants',
595 'saso_eventtickets_is_daychooser',
596 'saso_eventtickets_request_name_per_ticket',
597 'saso_eventtickets_request_name_per_ticket_mandatory',
598 'saso_eventtickets_request_value_per_ticket',
599 'saso_eventtickets_request_value_per_ticket_mandatory',
600 'saso_eventtickets_ticket_is_RTL',
601 'saso_eventtickets_list_formatter'
602 ];
603 foreach($keys_checkbox as $key) {
604 if( isset( $R[$key] ) ) {
605 update_post_meta( $id, $key, 'yes' );
606 } else {
607 delete_post_meta( $id, $key );
608 }
609 }
610
611 $keys_inputfields = [
612 'saso_eventtickets_event_location',
613 'saso_eventtickets_ticket_start_date',
614 'saso_eventtickets_ticket_start_time',
615 'saso_eventtickets_ticket_end_date',
616 'saso_eventtickets_ticket_end_time',
617 'saso_eventtickets_request_name_per_ticket_label',
618 'saso_eventtickets_request_value_per_ticket_label',
619 'saso_eventtickets_request_value_per_ticket_def',
620 'saso_eventtickets_list_formatter_values',
621 'saso_eventtickets_request_daychooser_per_ticket_label'
622 ];
623 foreach($keys_inputfields as $key) {
624 if( isset($R[$key]) && !empty( $R[$key] ) ) {
625 update_post_meta( $id, $key, sanitize_text_field($R[$key]) );
626 } else {
627 delete_post_meta( $id, $key );
628 }
629 }
630
631 $key = 'saso_eventtickets_daychooser_exclude_wdays';
632 if (isset($R[$key])) {
633 $array_to_save = [];
634 foreach($R[$key] as $v) {
635 $v = sanitize_text_field($v);
636 $array_to_save[] = $v;
637 }
638 update_post_meta( $id, $key, $array_to_save );
639 } else {
640 delete_post_meta( $id, $key );
641 }
642
643 $keys_number = [
644 'saso_eventtickets_ticket_max_redeem_amount',
645 'saso_eventtickets_ticket_amount_per_item',
646 'saso_eventtickets_daychooser_offset_start',
647 'saso_eventtickets_daychooser_offset_end'
648 ];
649 foreach($keys_number as $key) {
650 if( isset($R[$key]) && !empty($R[$key]) || $R[$key] == "0" ) {
651 $value = intval($R[$key]);
652 if ($value < 0) $value = 1;
653 update_post_meta( $id, $key, $value );
654 } else {
655 delete_post_meta( $id, $key );
656 }
657 }
658
659 $key = 'saso_eventtickets_ticket_is_ticket_info';
660 if( isset($R[$key]) && !empty( $R[$key] ) ) {
661 update_post_meta( $id, $key, wp_kses_post($R[$key]) );
662 } else {
663 delete_post_meta( $id, $key );
664 }
665 $key = 'saso_eventtickets_request_value_per_ticket_values';
666 if( isset($R[$key]) && !empty( $R[$key] ) ) {
667 $v = [];
668 foreach(explode("\n", $R[$key]) as $entry) {
669 $t = explode("|", $entry);
670 if (count($t) > 0) {
671 $t[0] = sanitize_key(trim($t[0]));
672 if (count($t) > 1) {
673 $t[1] = sanitize_key(trim($t[1]));
674 }
675 $v[] = join("|", $t);
676 }
677 }
678 update_post_meta( $id, $key, join("\n", $v));
679 } else {
680 delete_post_meta( $id, $key );
681 }
682
683 if ($this->MAIN->isPremium() && method_exists($this->MAIN->getPremiumFunctions(), 'saso_eventtickets_wc_save_fields')) {
684 $this->MAIN->getPremiumFunctions()->saso_eventtickets_wc_save_fields($id, $post);
685 }
686 }
687
688 private function hasTicketsInCart() {
689 foreach(WC()->cart->get_cart() as $cart_item ) {
690 // Check cart item for defined product Ids and applied coupon
691 $saso_eventtickets_list_id = get_post_meta($cart_item['product_id'], "saso_eventtickets_list", true);
692 if (!empty($saso_eventtickets_list_id)) {
693 return true;
694 }
695 }
696 return false;
697 }
698
699 public function hasTicketsInOrder($order) {
700 $items = $order->get_items();
701 // check if order contains tickets
702 foreach($items as $item_id => $item) {
703 if (get_post_meta($item->get_product_id(), 'saso_eventtickets_is_ticket', true) == "yes") {
704 return true;
705 }
706 }
707 return false;
708 }
709
710 public function hasTicketsInOrderWithTicketnumber($order) {
711 $items = $order->get_items();
712 // check if order contains tickets
713 foreach($items as $item_id => $item) {
714 if (get_post_meta($item->get_product_id(), 'saso_eventtickets_is_ticket', true) == "yes") {
715 $codes = wc_get_order_item_meta($item_id , '_saso_eventtickets_product_code',true);
716 if (!empty($codes)) {
717 return true;
718 }
719 }
720 }
721 return false;
722 }
723
724 public function getTicketsFromOrder($order) {
725 $products = [];
726 $items = $order->get_items();
727 // check if order contains tickets
728 foreach($items as $item_id => $item) {
729 $product_id = $item->get_product_id();
730 if (get_post_meta($product_id, 'saso_eventtickets_is_ticket', true) == "yes") {
731 $codes = wc_get_order_item_meta($item_id , '_saso_eventtickets_product_code',true);
732 $key = $product_id."_".$item_id;
733 $products[$key] = [
734 "quantity"=>$item->get_quantity(),
735 "codes"=>$codes,
736 "product_id"=>$product_id,
737 "order_item_id"=>$item_id];
738 }
739 }
740 return $products;
741 }
742
743 public function woocommerce_email_attachments($attachments, $email_id, $order) {
744 if ( ! is_a( $order, 'WC_Order' ) || ! isset( $email_id ) ) {
745 return $attachments;
746 }
747
748 $this->_attachments = [];
749
750 // ics file anhängen
751 $wcTicketAttachICSToMail = $this->getOptions()->isOptionCheckboxActive('wcTicketAttachICSToMail');
752 if ($wcTicketAttachICSToMail) {
753 // $email_id == 'customer_on_hold_order'
754 if (
755 $email_id == 'customer_completed_order' ||
756 $email_id == 'customer_note' ||
757 $email_id == 'customer_invoice' ||
758 $email_id == 'customer_processing_order'
759 ){
760 if (!class_exists("sasoEventtickets_Ticket")){
761 require_once("sasoEventtickets_Ticket.php");
762 }
763 $tickets = $this->getTicketsFromOrder($order);
764 // get ticket date if set
765 $dirname = get_temp_dir(); // pfad zu den dateien
766 if (wp_is_writable($dirname)) {
767 $dirname .= trailingslashit($this->getPrefix());
768 if (!file_exists($dirname)) {
769 // mkdir if not exists
770 wp_mkdir_p($dirname);
771 }
772 foreach($tickets as $key => $ticket) {
773 try {
774 $product_id = $ticket["product_id"];
775 $product = wc_get_product( $product_id );
776 $ticket_start_date = trim(get_post_meta( $product_id, 'saso_eventtickets_ticket_start_date', true ));
777 if (!empty($ticket_start_date)) {
778 $is_daychooser = get_post_meta( $product_id, 'saso_eventtickets_is_daychooser', true ) == "yes" ? true : false;
779 if ($is_daychooser) {
780 $codeObj = $this->getCore()->retrieveCodeByOrderItemId($ticket["order_item_id"]);
781 $codes = [];
782 if (!empty($ticket['codes'])) {
783 $codes = explode(",", $ticket['codes']);
784 }
785 foreach($codes as $code) {
786 try {
787 $codeObj = $this->getCore()->retrieveCodeByCode($code);
788 } catch (Exception $e) {
789 $this->MAIN->getAdmin()->logErrorToDB($e);
790 continue;
791 }
792 $contents = $this->MAIN->getTicketHandler()->generateICSFile($product, $codeObj);
793 // save file
794 $file = $dirname."ics_".$product_id."_".$code.".ics";
795 $ret = file_put_contents( $file, $contents );
796 // add attachments
797 $this->_attachments[] = $file;
798 }
799 } else {
800 $contents = $this->MAIN->getTicketHandler()->generateICSFile($product);
801 // save file
802 $file = $dirname."ics_".$product_id.".ics";
803 $ret = file_put_contents( $file, $contents );
804 // add attachments
805 $this->_attachments[] = $file;
806 }
807 }
808 } catch(Exception $e) {
809 $this->MAIN->getAdmin()->logErrorToDB($e);
810 }
811 }
812 }
813 }
814 }
815
816 $wcTicketBadgeAttachFileToMail = $this->getOptions()->isOptionCheckboxActive('wcTicketBadgeAttachFileToMail');
817 if ($wcTicketBadgeAttachFileToMail) {
818 $allowed_emails = $this->getOptions()->get_wcTicketAttachTicketToMailOf();
819 if (in_array($email_id, $allowed_emails)) {
820 $badgeHandler = $this->MAIN->getTicketBadgeHandler();
821 $tickets = $this->getTicketsFromOrder($order);
822 if (count($tickets)>0) {
823 $dirname = get_temp_dir(); // pfad zu den dateien
824 if (wp_is_writable($dirname)) {
825 $dirname .= trailingslashit($this->getPrefix());
826 if (!file_exists($dirname)) {
827 wp_mkdir_p($dirname);
828 }
829 $attachments_badges = [];
830 foreach($tickets as $key => $ticket) {
831 try {
832 $product_id = $ticket["product_id"];
833 $codes = [];
834 if (!empty($ticket['codes'])) {
835 $codes = explode(",", $ticket['codes']);
836 }
837 foreach($codes as $code) {
838 try {
839 $codeObj = $this->getCore()->retrieveCodeByCode($code);
840 } catch (Exception $e) {
841 continue;
842 }
843 $attachments_badges[] = $badgeHandler->getPDFTicketBadgeFilepath($codeObj, $dirname);
844 }
845
846 $wcTicketBadgeAttachFileToMailAsOnePDF = $this->getOptions()->getOptionValue("wcTicketBadgeAttachFileToMailAsOnePDF");
847 if ($wcTicketBadgeAttachFileToMailAsOnePDF && count($attachments_badges) > 1) {
848 $filename = "ticketbadges_".$codeObj['order_id'].".pdf";
849 $this->_attachments[] = $this->MAIN->getCore()->mergePDFs($attachments_badges, $filename, "F", false);
850 } else {
851 $this->_attachments = array_merge($this->_attachments, $attachments_badges);
852 }
853
854 } catch(Exception $e) {
855 $this->MAIN->getAdmin()->logErrorToDB($e);
856 }
857 }
858 }
859 }
860 }
861 }
862
863 $qrAttachQRImageToEmail = $this->getOptions()->isOptionCheckboxActive('qrAttachQRImageToEmail');
864 $qrAttachQRPdfToEmail = $this->getOptions()->isOptionCheckboxActive('qrAttachQRPdfToEmail');
865 if ($qrAttachQRImageToEmail || $qrAttachQRPdfToEmail) {
866 $allowed_emails = $this->getOptions()->get_wcTicketAttachTicketToMailOf();
867 if (in_array($email_id, $allowed_emails)) {
868 $qrHandler = $this->MAIN->getTicketQRHandler();
869 $tickets = $this->getTicketsFromOrder($order);
870 if (count($tickets)>0) {
871 $dirname = get_temp_dir(); // pfad zu den dateien
872 if (wp_is_writable($dirname)) {
873 $dirname .= trailingslashit($this->getPrefix());
874 if (!file_exists($dirname)) {
875 wp_mkdir_p($dirname);
876 }
877 $attachments_qrcodes_pdf = [];
878 $attachments_qrcodes_images = [];
879 foreach($tickets as $key => $ticket) {
880 try {
881 $product_id = $ticket["product_id"];
882 $codes = [];
883 if (!empty($ticket['codes'])) {
884 $codes = explode(",", $ticket['codes']);
885 }
886 foreach($codes as $code) {
887 try {
888 $codeObj = $this->getCore()->retrieveCodeByCode($code);
889 } catch (Exception $e) {
890 continue;
891 }
892 $metaObj = $this->MAIN->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj);
893 $ticket_id = $this->MAIN->getCore()->getTicketId($codeObj, $metaObj);
894 try {
895 if($qrAttachQRImageToEmail){
896 $attachments_qrcodes_images[] = $qrHandler->renderPNG($ticket_id, "F");
897 }
898 if($qrAttachQRPdfToEmail){
899 $attachments_qrcodes_pdf[] = $qrHandler->renderPDF($ticket_id, "F");
900 }
901 } catch (Exception $e) {
902 $this->MAIN->getAdmin()->logErrorToDB($e);
903 continue;
904 }
905 }
906
907 if (count($attachments_qrcodes_images) > 0) {
908 $this->_attachments = array_merge($this->_attachments, $attachments_qrcodes_images);
909 }
910
911 $qrAttachQRFilesToMailAsOnePDF = $this->getOptions()->getOptionValue("qrAttachQRFilesToMailAsOnePDF");
912 if ($qrAttachQRFilesToMailAsOnePDF && count($attachments_qrcodes_pdf) > 1) {
913 $filename = "ticketqrcodes_".$codeObj['order_id'].".pdf";
914 $this->_attachments[] = $this->MAIN->getCore()->mergePDFs($attachments_qrcodes_pdf, $filename, "F", false);
915 } else {
916 if (count($attachments_qrcodes_pdf) > 0) {
917 $this->_attachments = array_merge($this->_attachments, $attachments_qrcodes_pdf);
918 }
919 }
920 } catch(Exception $e) {
921 $this->MAIN->getAdmin()->logErrorToDB($e);
922 }
923 }
924 }
925 }
926 }
927 }
928
929 $_attachments = apply_filters( $this->MAIN->_add_filter_prefix.'woocommerce_email_attachments', $attachments, $email_id, $order );
930 if (count($_attachments) > 0) {
931 $this->_attachments = array_merge($this->_attachments, $_attachments);
932 }
933
934 $_attachments = apply_filters( $this->MAIN->_add_filter_prefix.'woocommerce-hooks_woocommerce_email_attachments', $_attachments, $attachments, $email_id, $order );
935
936 // attach
937 foreach($this->_attachments as $item) {
938 if (is_string($item)) {
939 if (file_exists($item)) $attachments[] = $item;
940 }
941 }
942
943 // add hook, to delete the attachments after the mail is sent
944 if (count($this->_attachments) > 0) {
945 add_action( 'wp_mail_succeeded', [$this, 'wp_mail_succeeded'], 10, 1 );
946 add_action( 'wp_mail_failed', [$this, 'wp_mail_failed'], 10, 1 );
947 }
948
949 return $attachments;
950 }
951
952 // not in used. Hook commented out at index.php
953 // will be also called if woocommerce_order_partially_refunded is called
954 public function woocommerce_update_order($order_id, $order) {
955 // attention, this can trigger a loop.
956 //$this->add_serialcode_to_order($order_id); // vlt wurden manuel produkte hinzugefügt
957 }
958
959 public function woocommerce_order_partially_refunded($order_id, $refund_id) {
960 if ($this->getOptions()->isOptionCheckboxActive('wcassignmentOrderItemRefund')) {
961 $order = wc_get_order( $order_id );
962
963 foreach ($order->get_items() as $item_id => $item) {
964 $product = $item->get_product();
965 if( $product == null ) continue;
966 $product_id = $item->get_product_id();
967
968 $isTicket = get_post_meta($product_id, 'saso_eventtickets_is_ticket', true) == "yes";
969 if ($isTicket == false) continue;
970 $variation_id = $item->get_variation_id();
971 if ($variation_id > 0) {
972 // check ob diese variation vom ticket ausgeschlossen ist
973 if (get_post_meta($variation_id, '_saso_eventtickets_is_not_ticket', true) == "yes") {
974 continue;
975 }
976 }
977
978 $item_qty_refunded = $order->get_qty_refunded_for_item( $item_id );
979 if ($item_qty_refunded >= 0) continue;
980
981 $existingCodes = wc_get_order_item_meta($item_id , '_saso_eventtickets_product_code', true);
982 if (empty($existingCodes)) continue;
983
984 // check how many codes should be there, with the refund
985 if ($item->get_variation_id() > 0) {
986 $saso_eventtickets_ticket_amount_per_item = intval(get_post_meta( $item->get_variation_id(), 'saso_eventtickets_ticket_amount_per_item', true ));
987 } else {
988 $saso_eventtickets_ticket_amount_per_item = intval(get_post_meta( $product_id, 'saso_eventtickets_ticket_amount_per_item', true ));
989 }
990 if ($saso_eventtickets_ticket_amount_per_item < 1) {
991 $saso_eventtickets_ticket_amount_per_item = 1;
992 }
993 $new_quantity = $item->get_quantity() + $item_qty_refunded; // new quantity without the refunded
994 $new_quantity *= $saso_eventtickets_ticket_amount_per_item;
995
996 $old_codes = explode(",", $existingCodes);
997 $count_codes = count($old_codes);
998 if ($count_codes > $new_quantity) {
999 $codes = array_slice($old_codes, 0, $new_quantity);
1000
1001 $public_ticket_ids_value = wc_get_order_item_meta($item_id , '_saso_eventtickets_public_ticket_ids', true);
1002 $existing_plublic_ticket_ids = explode(",", $public_ticket_ids_value);
1003 $public_ticket_ids = [];
1004 if (count($existing_plublic_ticket_ids) > $new_quantity) {
1005 $values = array_slice($existing_plublic_ticket_ids, 0, $new_quantity);
1006 foreach ($values as $public_ticket_id) {
1007 $public_ticket_id = trim($public_ticket_id);
1008 if (empty($public_ticket_id)) continue;
1009 $public_ticket_ids[] = $public_ticket_id;
1010 }
1011 }
1012
1013 // save new values
1014 wc_delete_order_item_meta( $item_id, '_saso_eventtickets_product_code' );
1015 wc_add_order_item_meta($item_id , '_saso_eventtickets_product_code', implode(",", $codes) ) ;
1016 wc_delete_order_item_meta( $item_id, "_saso_eventtickets_public_ticket_ids" );
1017 wc_add_order_item_meta($item_id , "_saso_eventtickets_public_ticket_ids", implode(",", $public_ticket_ids) ) ;
1018
1019 // delete tickets
1020 $codes_to_delete = array_slice($old_codes, $new_quantity);
1021 foreach ($codes_to_delete as $code) {
1022 $code = trim($code);
1023 if (empty($code)) continue;
1024
1025 // remove used info - if it is a real ticket number and not the free max usage message
1026 $data = ['code'=>$code];
1027 try {
1028 $this->getAdmin()->removeUsedInformationFromCode($data);
1029 $this->getAdmin()->removeWoocommerceOrderInfoFromCode($data);
1030 $this->getAdmin()->removeWoocommerceRstrPurchaseInfoFromCode($data);
1031 $order->add_order_note( sprintf(/* translators: %s: ticket number */esc_html__('Refunded ticket(s). Ticket number %s removed for order item id: %s.', 'event-tickets-with-ticket-scanner'), esc_attr($code), esc_attr($item_id)) );
1032 } catch (Exception $e) {
1033 $this->MAIN->getAdmin()->logErrorToDB($e);
1034 }
1035 }
1036 }
1037 } // endfor each
1038 }
1039 }
1040
1041 public function woocommerce_order_status_changed($order_id,$old_status,$new_status) {
1042 if ($new_status != "refunded" && $new_status != "cancelled" && $new_status != "wc-refunded" && $new_status != "wc-cancelled") {
1043 $this->add_serialcode_to_order($order_id); // vlt wurden manuel produkte hinzugefügt
1044 }
1045 if ($new_status == "cancelled" || $new_status == "wc-cancelled" || $new_status == "wc-refunded" || $new_status == "refunded") {
1046 if ($this->getOptions()->isOptionCheckboxActive('wcRestrictFreeCodeByOrderRefund')) {
1047 $order = wc_get_order( $order_id );
1048 $items = $order->get_items();
1049 foreach ( $items as $item_id => $item ) {
1050 $this->woocommerce_delete_order_item($item_id);
1051 }
1052 }
1053 }
1054 do_action( $this->MAIN->_do_action_prefix.'woocommerce-hooks_woocommerce_order_status_changed', $order_id, $old_status, $new_status );
1055 }
1056
1057 public function woocommerce_order_item_display_meta_key( $display_key, $meta, $item ) {
1058 // display within the order
1059
1060 if ( is_admin() && $item->get_type() === 'line_item'){
1061 // Change displayed label for specific order item meta key
1062 if($meta->key === '_saso_eventtickets_product_code' ) {
1063 $isTicket = $item->get_meta('_saso_eventtickets_is_ticket') == 1 ? true : false;
1064 if ($isTicket) {
1065 $display_key = __("Ticket number(s)", 'event-tickets-with-ticket-scanner');
1066 } else {
1067 $display_key = _x("Code", "noun", 'event-tickets-with-ticket-scanner');
1068 }
1069 }
1070 if ($meta->key === "_saso_eventtickets_public_ticket_ids") {
1071 $display_key = __("Public Ticket Id(s)", 'event-tickets-with-ticket-scanner');
1072 }
1073 if($meta->key === '_saso_eventticket_code_list' ) {
1074 $display_key = __("List ID", 'event-tickets-with-ticket-scanner');
1075 }
1076 if ($meta->key === "_saso_eventtickets_is_ticket") {
1077 $display_key = __("Is Ticket", 'event-tickets-with-ticket-scanner');
1078 }
1079 if ($meta->key === "_saso_eventtickets_daychooser") {
1080 $display_key = __("Day(s) per ticket", 'event-tickets-with-ticket-scanner');
1081 }
1082
1083 // label for purchase restriction code
1084 if($meta->key === $this->meta_key_codelist_restriction_order_item ) {
1085 $display_key = esc_attr($this->getOptions()->getOptionValue('wcRestrictPrefixTextCode'));
1086 }
1087 }
1088
1089 $display_key = apply_filters( $this->MAIN->_add_filter_prefix.'woocommerce-hooks_woocommerce_order_item_display_meta_key', $display_key, $meta, $item );
1090
1091 return $display_key;
1092 }
1093
1094 public function woocommerce_order_item_display_meta_value($meta_value, $meta, $item) {
1095 // zeigen in der Order den Wert an
1096
1097 if( is_admin() && $item->get_type() === 'line_item') {
1098 if ($meta->key === '_saso_eventtickets_product_code' ) {
1099 $codes = explode(",", $meta_value);
1100 $codes_ = [];
1101 foreach($codes as $c) {
1102 $codes_[] = '<a target="_blank" href="admin.php?page=event-tickets-with-ticket-scanner&code='.urlencode($c).'">'.$c.'</a>';
1103 }
1104 $meta_value = implode(", ", $codes_);
1105 } else if ($meta->key === '_saso_eventtickets_public_ticket_ids') {
1106 $codes = explode(",", $meta_value);
1107 $_codes = [];
1108 foreach($codes as $c) {
1109 $c = trim($c);
1110 if (!empty($c)) {
1111 $_codes[] = $c;
1112 }
1113 }
1114 if (count($_codes) > 0) {
1115 $meta_value = implode(", ", $_codes);
1116 } else {
1117 $meta_value = '-';
1118 }
1119 } else if ($meta->key === '_saso_eventtickets_is_ticket' ) {
1120 $meta_value = $meta_value == 1 ? "Yes" : "No";
1121 } else if ($meta->key === "_saso_eventtickets_daychooser") {
1122 $codes = explode(",", $meta_value);
1123 $_codes = [];
1124 foreach($codes as $c) {
1125 $c = trim($c);
1126 if (!empty($c)) {
1127 $_codes[] = $c;
1128 }
1129 }
1130 if (count($_codes) > 0) {
1131 $meta_value = implode(", ", $_codes);
1132 } else {
1133 $meta_value = '-';
1134 }
1135 }
1136 }
1137 $meta_value = apply_filters( $this->MAIN->_add_filter_prefix.'woocommerce-hooks_woocommerce_order_item_display_meta_value', $meta_value, $meta, $item );
1138 return $meta_value;
1139 }
1140
1141 public function manage_edit_product_columns($columns) {
1142 $new_columns = (is_array($columns)) ? $columns : array();
1143 $new_columns['SASO_EVENTTICKETS_LIST_COLUMN'] = _x('Ticket List', 'label', 'event-tickets-with-ticket-scanner');
1144 return $new_columns;
1145 }
1146 public function manage_product_posts_custom_column($column) {
1147 global $post;
1148
1149 if ($column == 'SASO_EVENTTICKETS_LIST_COLUMN') {
1150 $code_list_ids = get_post_meta($post->ID, 'saso_eventtickets_list', true);
1151
1152 $lists = $this->getAdmin()->getLists();
1153 $dropdown_list = array('' => '-');
1154 foreach ($lists as $key => $list) {
1155 $dropdown_list[$list['id']] = $list['name'];
1156 }
1157
1158 if (isset($code_list_ids) && !empty($code_list_ids)) {
1159 echo !empty( $dropdown_list[$code_list_ids]) ? esc_html($dropdown_list[$code_list_ids]) : '-';
1160 } else {
1161 echo "-";
1162 }
1163 }
1164 }
1165 public function manage_edit_product_sortable_columns($columns) {
1166 $custom = array(
1167 'SASO_EVENTTICKETS_LIST_COLUMN' => 'saso_eventtickets_list'
1168 );
1169 return wp_parse_args($custom, $columns);
1170 }
1171
1172 public function wpo_wcpdf_after_item_meta( $template_type, $item, $order ) {
1173 $isPaid = SASO_EVENTTICKETS::isOrderPaid($order);
1174 if ($isPaid) {
1175 $code = wc_get_order_item_meta($item['item_id'] , $this->meta_key_codelist_restriction_order_item, true);
1176 if (!empty($code)) {
1177 if (!$this->getOptions()->isOptionCheckboxActive('wcRestrictDoNotPutOnPDF')) {
1178 $preText = $this->getOptions()->getOptionValue('wcRestrictPrefixTextCode');
1179 echo '<div class="product-serial-code">'.esc_html($preText).' '. esc_attr($code).'</div>';
1180 }
1181 }
1182
1183 $codeObjects_cache = [];
1184
1185 $code = wc_get_order_item_meta($item['item_id'] , '_saso_eventtickets_product_code',true);
1186 if (!empty($code)) {
1187
1188 if ($this->getOptions()->isOptionCheckboxActive('wcassignmentDoNotPutOnPDF') == false) {
1189 $code_ = explode(",", $code);
1190 array_walk($code_, "trim");
1191
1192 $isTicket = wc_get_order_item_meta($item['item_id'] , '_saso_eventtickets_is_ticket',true) == 1 ? true : false;
1193 $key = 'wcassignmentPrefixTextCode';
1194 if ($isTicket) $key = 'wcTicketPrefixTextCode';
1195 $preText = $this->getOptions()->getOptionValue($key);
1196
1197 $wcassignmentDoNotPutCVVOnPDF = $this->getOptions()->isOptionCheckboxActive('wcassignmentDoNotPutCVVOnPDF');
1198
1199 if ($isTicket) {
1200 $product_id = $item['product_id'];
1201 $display_date = $this->getOptions()->isOptionCheckboxActive('wcTicketDisplayDateOnMail');
1202 $is_daychooser = get_post_meta($product_id, "saso_eventtickets_is_daychooser", true) == "yes";
1203
1204 if ($display_date) {
1205 if (!class_exists("sasoEventtickets_Ticket")){
1206 require_once("sasoEventtickets_Ticket.php");
1207 }
1208 $product = wc_get_product( $product_id );
1209 // check if the product is a day chooser
1210 if (!$is_daychooser) {
1211 $date_str = $this->MAIN->getTicketHandler()->displayTicketDateAsString($product);
1212 if (!empty($date_str)) echo $date_str."<br>";
1213 }
1214 }
1215
1216 $wcTicketBadgeLabelDownload = $this->MAIN->getOptions()->getOptionValue('wcTicketBadgeLabelDownload');
1217 $code_size = count($code_);
1218 $counter = 0;
1219 $mod = 40;
1220 foreach($code_ as $c) {
1221 if (!empty($c)) {
1222 $counter++;
1223
1224 if (isset($codeObjects_cache[$c])) {
1225 $codeObj = $codeObjects_cache[$c];
1226 } else {
1227 $codeObj = $this->getCore()->retrieveCodeByCode($c);
1228 $codeObjects_cache[$c] = $codeObj;
1229 }
1230 $metaObj = $this->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj);
1231
1232 $url = $metaObj['wc_ticket']['_url'];
1233
1234 //echo '<p class="product-serial-code">'.esc_html($preText).' <b>'.esc_html($c).'</b>';
1235 echo '<br>'.esc_html($preText).' <b>'.esc_html($c).'</b>';
1236 if (!empty($codeObj['cvv']) && !$wcassignmentDoNotPutCVVOnPDF) {
1237 echo " CVV: <b>".esc_html($codeObj['cvv']).'</b>';
1238 }
1239
1240 if ($display_date && $is_daychooser) {
1241 $daychooser_date = $this->MAIN->getTicketHandler()->displayDayChooserDateAsString($product, $codeObj);
1242 if (!empty($daychooser_date)) echo $daychooser_date."<br>";
1243 }
1244
1245 if (!$this->getOptions()->isOptionCheckboxActive('wcTicketDontDisplayDetailLinkOnMail')) {
1246 $mod = 8;
1247 if (!empty($url)) {
1248 echo '<br><b>'.esc_html__('Ticket Detail', 'event-tickets-with-ticket-scanner').':</b> ' . esc_url($url) . '<br>';
1249 }
1250 }
1251
1252 if (!$this->getOptions()->isOptionCheckboxActive('wcTicketBadgeAttachLinkToMail')) {
1253 $mod = 8;
1254 if (!empty($url)) {
1255 echo '<br><b>'.esc_html($wcTicketBadgeLabelDownload).':</b> ' . esc_url($url) . '?badge<br>';
1256 }
1257 }
1258 //echo '</p>';
1259
1260 if ($code_size > $mod && $counter % $mod == 0) {
1261 echo '<div style="page-break-before: always;"></div>';
1262 }
1263 }
1264 }
1265
1266 } else {
1267 $sep = $this->getOptions()->getOptionValue('wcassignmentDisplayCodeSeperatorPDF');
1268 $ccodes = [];
1269 foreach($code_ as $c) {
1270 if (!empty($c)) {
1271 if (!$wcassignmentDoNotPutCVVOnPDF) {
1272 if (isset($codeObjects_cache[$c])) {
1273 $codeObj = $codeObjects_cache[$c];
1274 } else {
1275 $codeObj = $this->getCore()->retrieveCodeByCode($c);
1276 $codeObjects_cache[$c] = $codeObj;
1277
1278 }
1279 if (!empty($codeObj['cvv'])) {
1280 $ccodes[] = esc_html($c." CVV: ".$codeObj['cvv']);
1281 } else {
1282 $ccodes[] = esc_html($c);
1283 }
1284 } else {
1285 $ccodes[] = esc_html($c);
1286 }
1287 }
1288 }
1289 $code_text = implode($sep, $ccodes);
1290 echo '<div class="product-serial-code">'.esc_html($preText).' '. esc_html($code_text).'</div>';
1291 }
1292 }
1293 }
1294 } // not paid
1295 }
1296
1297 private function set_wcTicketSetOrderToCompleteIfAllOrderItemsAreTickets($order) {
1298 if ($this->getOptions()->isOptionCheckboxActive('wcTicketSetOrderToCompleteIfAllOrderItemsAreTickets')) {
1299 $order_status = $order->get_status();
1300 //if ($order_status != "completed" && $order_status != "wc-completed") {
1301 if ($order_status == "processing" || $order_status == "wc-processing") {
1302 $items = $order->get_items();
1303 if (count($items) > 0) {
1304 $all_items_are_tickets = true;
1305 foreach($items as $l_item) {
1306 $product_id = $l_item->get_product_id();
1307 if (get_post_meta($product_id, 'saso_eventtickets_is_ticket', true) == "yes") {
1308 } else {
1309 $all_items_are_tickets = false;
1310 break;
1311 }
1312 }
1313 if ($all_items_are_tickets) {
1314 $order->update_status("completed");
1315 }
1316 }
1317 }
1318 }
1319 do_action( $this->MAIN->_do_action_prefix.'woocommerce-hooks_set_wcTicketSetOrderToCompleteIfAllOrderItemsAreTickets', $order );
1320 return $order;
1321 }
1322 public function woocommerce_order_item_meta_start($item_id, $item, $order, $plain_text=false) {
1323 $this->add_serialcode_to_order($order->get_id()); // falls noch welche fehlen, dann vor der E-Mail noch hinzufügen
1324
1325 $order = $this->set_wcTicketSetOrderToCompleteIfAllOrderItemsAreTickets($order);
1326
1327 $isPaid = SASO_EVENTTICKETS::isOrderPaid($order);
1328 if ($isPaid) {
1329
1330 $codeObjects_cache = [];
1331 $product_id = $item->get_product_id();
1332
1333 $sale_restriction_code = wc_get_order_item_meta($item_id , $this->meta_key_codelist_restriction_order_item, true);
1334 if (!empty($sale_restriction_code)) {
1335 $preText = $this->getOptions()->getOptionValue('wcRestrictPrefixTextCode');
1336 if ($plain_text) {
1337 echo "\n".esc_html($preText).' '. esc_attr($sale_restriction_code);
1338 } else {
1339 echo '<div class="product-restriction-serial-code">'.esc_html($preText).' '. esc_attr($sale_restriction_code).'</div>';
1340 }
1341 }
1342
1343 $displaySerial = false;
1344 $code = "";
1345 $preText = "";
1346 if ($this->getOptions()->isOptionCheckboxActive('wcassignmentDoNotPutOnEmail') == false) {
1347 $isTicket = wc_get_order_item_meta($item_id , '_saso_eventtickets_is_ticket',true) == 1 ? true : false;
1348 if ($isTicket) {
1349 $code = wc_get_order_item_meta($item_id , '_saso_eventtickets_product_code',true);
1350 if (!empty($code)) {
1351 $preText = $this->getOptions()->getOptionValue('wcTicketPrefixTextCode');
1352 $displaySerial = true;
1353 }
1354 } else { // serial?
1355 /*
1356 $code = wc_get_order_item_meta($item_id , '_saso_eventtickets_product_code',true);
1357 if (!empty($code)) {
1358 $preText = $this->getOptions()->getOptionValue('wcassignmentPrefixTextCode');
1359 $displaySerial = true;
1360 }
1361 */
1362 }
1363 }
1364 if ($displaySerial) {
1365 $product = null;
1366 $code_ = explode(",", $code);
1367 array_walk($code_, "trim");
1368 if ($isTicket) {
1369 $wcassignmentDoNotPutCVVOnEmail = $this->getOptions()->isOptionCheckboxActive('wcassignmentDoNotPutCVVOnEmail');
1370 $wcTicketDontDisplayDetailLinkOnMail = $this->getOptions()->isOptionCheckboxActive('wcTicketDontDisplayDetailLinkOnMail');
1371 $wcTicketDontDisplayPDFButtonOnMail = $this->getOptions()->isOptionCheckboxActive('wcTicketDontDisplayPDFButtonOnMail');
1372 $wcTicketBadgeAttachLinkToMail = $this->getOptions()->isOptionCheckboxActive('wcTicketBadgeAttachLinkToMail');
1373 $is_daychooser = get_post_meta($product_id, "saso_eventtickets_is_daychooser", true) == "yes";
1374
1375 if ($this->getOptions()->isOptionCheckboxActive('wcTicketDisplayDateOnMail')) {
1376 if (!class_exists("sasoEventtickets_Ticket")){
1377 require_once("sasoEventtickets_Ticket.php");
1378 }
1379
1380 $product = $item->get_product();
1381 // check if the product is a day chooser
1382 if (!$is_daychooser) {
1383 $date_str = $this->MAIN->getTicketHandler()->displayTicketDateAsString($product);
1384 if (!empty($date_str)) echo $date_str."<br>";
1385 }
1386 }
1387
1388 $labelNamePerTicket_label = null;
1389 $labelValuePerTicket_label = null;
1390 $labelDayChooser_label = null;
1391
1392 $a = 0;
1393 foreach($code_ as $c) {
1394 $a++;
1395 if (!empty($c)) {
1396 $cvv = "";
1397 $url = "";
1398 $codeObj = null;
1399 $metaObj = null;
1400 try { // kann sein, dass keine free tickets mehr verfügbar sind
1401 if (isset($codeObjects_cache[$c])) {
1402 $codeObj = $codeObjects_cache[$c];
1403 } else {
1404 $codeObj = $this->getCore()->retrieveCodeByCode($c);
1405 $codeObjects_cache[$c] = $codeObj;
1406
1407 }
1408 $metaObj = $this->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj);
1409 $url = $metaObj['wc_ticket']['_url'];
1410 $cvv = $codeObj['cvv'];
1411 } catch (Exception $e) {
1412 $this->MAIN->getAdmin()->logErrorToDB($e, "", "issues with the order email. Code: ".$c.". Cannot retrieve code object and/or meta object.");
1413 }
1414
1415 $parameter_add = "?";
1416 if (strpos(" ".$url, "?") > 0) {
1417 $parameter_add = "&";
1418 }
1419
1420 $ticket_info_text = "";
1421 if ($metaObj != null) {
1422 if ($product == null) {
1423 $product = $item->get_product();
1424 }
1425 $name_per_ticket = $metaObj['wc_ticket']['name_per_ticket'];
1426 if (!empty($name_per_ticket)) {
1427 if ($labelNamePerTicket_label == null) {
1428 $labelNamePerTicket_label = esc_attr($this->MAIN->getTicketHandler()->getLabelNamePerTicket($product->get_id()));
1429 }
1430 $labelNamePerTicket = str_replace("{count}", $a, $labelNamePerTicket_label);
1431 $ticket_info_text = $labelNamePerTicket." ".esc_html($name_per_ticket);
1432 }
1433 $value_per_ticket = $metaObj['wc_ticket']['value_per_ticket'];
1434 if (!empty($value_per_ticket)) {
1435 if ($labelValuePerTicket_label == null) {
1436 $labelValuePerTicket_label = esc_attr($this->MAIN->getTicketHandler()->getLabelValuePerTicket($product->get_id()));
1437 }
1438 $labelValuePerTicket = str_replace("{count}", $a, $labelValuePerTicket_label);
1439 if ($ticket_info_text != "") $ticket_info_text .= "<br>";
1440 $ticket_info_text .= $labelValuePerTicket." ".esc_html($value_per_ticket);
1441 }
1442 $day_chooser = $metaObj['wc_ticket']['day_per_ticket'];
1443 if (!empty($day_chooser) && $metaObj['wc_ticket']['is_daychooser'] == 1) {
1444 if ($labelDayChooser_label == null) {
1445 $labelDayChooser_label = esc_attr($this->MAIN->getTicketHandler()->getLabelDaychooserPerTicket($product->get_id()));
1446 }
1447 if (!empty($ticket_info_text)) $ticket_info_text .= "<br>";
1448 $labelDayChooser = str_replace("{count}", $a, $labelDayChooser_label);
1449 if ($ticket_info_text != "") $ticket_info_text .= "<br>";
1450 $ticket_info_text .= $labelDayChooser." ".esc_html($day_chooser);
1451 }
1452 }
1453
1454 //$is_thankyoupage = is_wc_endpoint_url( 'order-received' );
1455
1456 if ($plain_text) {
1457 if (!empty($ticket_info_text)) {
1458 echo "\n".esc_html(str_replace($ticket_info_text, "<br>", "\n"));
1459 }
1460 echo "\n".esc_html($preText).' '.esc_attr($c);
1461 if (!empty($cvv) && !$wcassignmentDoNotPutCVVOnEmail) {
1462 echo "\nCVV: ".esc_html($cvv);
1463 }
1464 if (!empty($url) && !$wcTicketDontDisplayDetailLinkOnMail) {
1465 echo "\n".esc_html__('Ticket Detail', 'event-tickets-with-ticket-scanner').": " . esc_url($url);
1466 }
1467 if (!empty($url) && !$wcTicketDontDisplayPDFButtonOnMail) {
1468 $dlnbtnlabel = $this->getOptions()->getOptionValue('wcTicketLabelPDFDownload');
1469 echo "\n" . esc_html($dlnbtnlabel) . " " . esc_url($url).$parameter_add.'pdf';
1470 }
1471 if (!empty($url) && $wcTicketBadgeAttachLinkToMail ) {
1472 $dlnbtnlabel = $this->getOptions()->getOptionValue('wcTicketBadgeLabelDownload');
1473 echo "\n" . esc_html($dlnbtnlabel) . " " . esc_url($url).$parameter_add.'badge';
1474 }
1475 } else {
1476 echo '<div class="product-serial-code" style="padding-bottom:15px;">';
1477 if (!empty($ticket_info_text)) {
1478 echo $ticket_info_text."<br>";
1479 }
1480 echo esc_html($preText)." ";
1481 if (empty($url) || $wcTicketDontDisplayDetailLinkOnMail) {
1482 echo esc_html($c);
1483 } else {
1484 echo '<br><a target="_blank" href="'.esc_url($url).'">'.esc_html($c).'</a> ';
1485 }
1486 if (!empty($cvv) && !$wcassignmentDoNotPutCVVOnEmail) {
1487 echo "CVV: ".esc_html($cvv);
1488 }
1489 echo '<p>';
1490 if (!empty($url) && !$wcTicketDontDisplayPDFButtonOnMail) {
1491 $dlnbtnlabel = $this->getOptions()->getOptionValue('wcTicketLabelPDFDownload');
1492 echo '<br><a target="_blank" href="'.esc_url($url).$parameter_add.'pdf"><b>'.esc_html($dlnbtnlabel).'</b></a>';
1493 }
1494 if (!empty($url) && $wcTicketBadgeAttachLinkToMail ) {
1495 $dlnbtnlabel = $this->getOptions()->getOptionValue('wcTicketBadgeLabelDownload');
1496 echo '<br><a target="_blank" href="'.esc_url($url).$parameter_add.'badge"><b>'.esc_html($dlnbtnlabel).'</b></a>';
1497 }
1498 echo '</p>';
1499 echo '</div>';
1500 }
1501 }
1502 }
1503 } else { // serial
1504 /*
1505 $sep = $this->getOptions()->getOptionValue('wcassignmentDisplayCodeSeperator');
1506 $ccodes = [];
1507 foreach($code_ as $c) {
1508 if (!$wcassignmentDoNotPutCVVOnEmail) {
1509 $codeObj = $this->getCore()->retrieveCodeByCode($c);
1510 if (!empty($codeObj['cvv'])) {
1511 $ccodes[] = esc_html($c." CVV: ".$codeObj['cvv']);
1512 } else {
1513 $ccodes[] = esc_html($c);
1514 }
1515 } else {
1516 $ccodes[] = esc_html($c);
1517 }
1518 }
1519 $code_text = implode($sep, $ccodes);
1520 if ($plain_text) {
1521 echo "\n".esc_html($preText).' '.esc_attr($code_text);
1522 } else {
1523 echo '<div class="product-serial-code">'.esc_html($preText).' '.esc_html($code_text).'</div>';
1524 }
1525 */
1526 }
1527 }
1528
1529 do_action( $this->MAIN->_do_action_prefix.'woocommerce-hooks_woocommerce_order_item_meta_start', $item_id, $item, $order, $plain_text );
1530 } // not paid
1531 }
1532
1533 function woocommerce_email_order_meta ($order, $sent_to_admin, $plain_text, $email) {
1534 $allowed_emails = $this->getOptions()->get_wcTicketAttachTicketToMailOf();
1535 if (is_array($allowed_emails) && in_array($email->id, $allowed_emails)) {
1536
1537 $isHeaderAdded = false;
1538 $hasTickets = false;
1539
1540 $wcTicketDisplayDownloadAllTicketsPDFButtonOnMail = $this->getOptions()->isOptionCheckboxActive('wcTicketDisplayDownloadAllTicketsPDFButtonOnMail');
1541 if ($wcTicketDisplayDownloadAllTicketsPDFButtonOnMail) {
1542 $hasTickets = $this->hasTicketsInOrderWithTicketnumber($order);
1543 if ($hasTickets) {
1544 $url = $this->getCore()->getOrderTicketsURL($order);
1545 $dlnbtnlabel = $this->getOptions()->getOptionValue('wcTicketLabelPDFDownload');
1546 $dlnbtnlabelHeading = $this->getOptions()->getOptionValue('wcTicketLabelPDFDownloadHeading');
1547 echo '<h2>'.esc_html($dlnbtnlabelHeading).'</h2>';
1548 echo '<p><a target="_blank" href="'.esc_url($url).'"><b>'.esc_html($dlnbtnlabel).'</b></a></p>';
1549 $isHeaderAdded = true;
1550 }
1551 }
1552
1553 $wcTicketDisplayOrderTicketsViewLinkOnMail = $this->getOptions()->isOptionCheckboxActive('wcTicketDisplayOrderTicketsViewLinkOnMail');
1554 if ($wcTicketDisplayOrderTicketsViewLinkOnMail) {
1555 if ($hasTickets == null) {
1556 $hasTickets = $this->hasTicketsInOrderWithTicketnumber($order);
1557 }
1558 if ($hasTickets) {
1559 $url = $this->getCore()->getOrderTicketsURL($order, "ordertickets-");
1560 $dlnbtnlabel = $this->getOptions()->getOptionValue('wcTicketLabelOrderDetailView');
1561 if (!$isHeaderAdded) {
1562 $dlnbtnlabelHeading = $this->getOptions()->getOptionValue('wcTicketLabelPDFDownloadHeading');
1563 echo '<h2>'.esc_html($dlnbtnlabelHeading).'</h2>';
1564 }
1565 echo '<p><a target="_blank" href="'.esc_url($url).'"><b>'.esc_html($dlnbtnlabel).'</b></a></p>';
1566 }
1567 }
1568
1569 do_action( $this->MAIN->_do_action_prefix.'woocommerce-hooks_woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );
1570 }
1571 }
1572
1573 private function delete_woocommerce_email_attachments() {
1574 $dirname = get_temp_dir().$this->getPrefix(); // pfad zu den dateien
1575 foreach($this->_attachments as $item) {
1576 try {
1577 if (file_exists($item) && dirname($item) == $dirname) @unlink($item);
1578 } catch(Exception $e) {
1579 $this->MAIN->getAdmin()->logErrorToDB($e);
1580 }
1581 }
1582 $this->_attachments = [];
1583 }
1584 public function wp_mail_failed($wp_error) {
1585 $this->delete_woocommerce_email_attachments();
1586 }
1587 public function wp_mail_succeeded($mail_data) {
1588 $this->delete_woocommerce_email_attachments();
1589 }
1590
1591 public function woocommerce_new_order($order_id) {
1592 if (WC() != null && WC()->session != null) {
1593 WC()->session->__unset('saso_eventtickets_request_name_per_ticket');
1594 WC()->session->__unset('saso_eventtickets_request_value_per_ticket');
1595 WC()->session->__unset('saso_eventtickets_request_daychooser');
1596 do_action( $this->MAIN->_do_action_prefix.'woocommerce-hooks_woocommerce_new_order', $order_id );
1597 }
1598 }
1599
1600 public function add_meta_boxes() {
1601 global $post_type;
1602 global $post;
1603
1604 $screen = $post_type;
1605 if ($screen == null) { // add HPOS support from woocommerce
1606 $screen = class_exists( '\Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController' ) && wc_get_container()->get( CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled()
1607 ? wc_get_page_screen_id( 'shop-order' )
1608 : 'shop_order';
1609 }
1610
1611 if( $screen == 'product' ) {
1612 if( $this->isTicket() == false ) return;
1613 add_meta_box(
1614 $this->getPrefix()."_wc_product_webhook", // Unique ID
1615 esc_html_x('Event Tickets', 'title', 'event-tickets-with-ticket-scanner'), // Box title
1616 [$this, 'wc_product_display_side_box'], // Content callback, must be of type callable
1617 $screen,
1618 'side',
1619 'high'
1620 );
1621 } elseif ($screen == "shop_order" || $screen == "woocommerce_page_wc-orders") {
1622 add_meta_box(
1623 $this->getPrefix()."_wc_order_webhook_basic", // Unique ID
1624 esc_html_x('Event Tickets', 'title', 'event-tickets-with-ticket-scanner'), // Box title
1625 [$this, 'wc_order_display_side_box'], // Content callback, must be of type callable
1626 $screen,
1627 'side',
1628 'high'
1629 );
1630 }
1631 }
1632
1633 public function wc_product_display_side_box() {
1634 ?>
1635 <p>Download Event Flyer</p>
1636 <button disabled data-id="<?php echo esc_attr($this->getPrefix()."btn_download_flyer"); ?>" class="button button-primary">Download Event Flyer</button>
1637 <p>Download ICS File (cal file)</p>
1638 <button disabled data-id="<?php echo esc_attr($this->getPrefix()."btn_download_ics"); ?>" class="button button-primary">Download ICS File</button>
1639 <p>Display all Tickets Infos</p>
1640 <button disabled data-id="<?php echo esc_attr($this->getPrefix()."btn_download_ticket_infos"); ?>" class="button button-primary">Print Ticket Infos</button>
1641 <?php
1642 do_action( $this->MAIN->_do_action_prefix.'wc_product_display_side_box', [] );
1643 }
1644
1645 public function wc_order_display_side_box( $post_or_order_object ) {
1646 $order = ( $post_or_order_object instanceof WP_Post ) ? wc_get_order( $post_or_order_object->ID ) : $post_or_order_object;
1647 if ($order && $this->hasTicketsInOrder($order)) {
1648 $this->wc_order_addJSFileAndHandlerBackend($order);
1649 ?>
1650 <p>Download All Tickets in one PDF</p>
1651 <button disabled data-id="<?php echo esc_attr($this->getPrefix()."btn_download_alltickets_one_pdf"); ?>" class="button button-primary">Download Tickets</button>
1652 <p>Remove all tickets from the order</p>
1653 <button disabled data-id="<?php echo esc_attr($this->getPrefix()."btn_remove_tickets"); ?>" class="button button-danger">Remove Tickets</button>
1654 <p>Remove all non-tickets from the order</p>
1655 <button disabled data-id="<?php echo esc_attr($this->getPrefix()."btn_remove_non_tickets"); ?>" class="button button-danger">Remove Ticket Placeholders</button>
1656 <?php
1657 do_action( $this->MAIN->_do_action_prefix.'wc_order_display_side_box', [] );
1658 } else {
1659 ?>
1660 <p>No tickets in this order</p>
1661 <?php
1662 }
1663 }
1664
1665 private function wc_order_addJSFileAndHandlerBackend($order) {
1666 $tickets = $this->getTicketsFromOrder($order);
1667 wp_enqueue_style("wp-jquery-ui-dialog");
1668 wp_enqueue_media(); // damit der media chooser von wordpress geladen wird
1669 wp_register_script(
1670 $this->MAIN->getPrefix().'WC_Order_Ajax_Backend_Basic',
1671 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'wc_backend.js?_v='.$this->MAIN->getPluginVersion(),
1672 array( 'jquery', 'jquery-ui-dialog', 'jquery-blockui', 'wp-i18n' ),
1673 (current_user_can("administrator") ? current_time("timestamp") : $this->MAIN->getPluginVersion()),
1674 true );
1675 wp_set_script_translations($this->MAIN->getPrefix().'WC_Order_Ajax_Backend_Basic', 'event-tickets-with-ticket-scanner', __DIR__.'/languages');
1676 wp_localize_script(
1677 $this->MAIN->getPrefix().'WC_Order_Ajax_Backend_Basic',
1678 'Ajax_sasoEventtickets_wc', // name der js variable
1679 [
1680 'ajaxurl' => admin_url( 'admin-ajax.php' ),
1681 '_plugin_home_url' =>plugins_url( "",__FILE__ ),
1682 'prefix'=>$this->MAIN->getPrefix(),
1683 'nonce' => wp_create_nonce( $this->MAIN->_js_nonce ),
1684 'action' => $this->MAIN->getPrefix().'_executeWCBackend',
1685 'product_id'=>0,
1686 'order_id'=>$order != null ? $order->get_id() : 0,
1687 'scope'=>'order',
1688 '_backendJS'=>trailingslashit( plugin_dir_url( __FILE__ ) ) . 'backend.js?_v='.$this->MAIN->getPluginVersion(),
1689 'tickets'=>$tickets
1690 ] // werte in der js variable
1691 );
1692 wp_enqueue_script($this->MAIN->getPrefix().'WC_Order_Ajax_Backend_Basic');
1693 }
1694
1695 function add_serialcode_to_order($order_id) {
1696
1697 if ( ! $order_id ) return;
1698
1699 // Getting an instance of the order object
1700 $order = wc_get_order( $order_id );
1701
1702 $create_tickets = SASO_EVENTTICKETS::isOrderPaid($order);
1703 $ok_order_statuses = $this->getOptions()->getOptionValue('wcTicketAddToOrderOnlyWithOrderStatus');
1704 if (is_array($ok_order_statuses) && count($ok_order_statuses) > 0) {
1705 $order_status = $order->get_status();
1706 $create_tickets = in_array($order_status, $ok_order_statuses);
1707 }
1708 if ($create_tickets == false) {
1709 $param_data = SASO_EVENTTICKETS::getRequestPara('data');
1710 if (SASO_EVENTTICKETS::issetRPara('a_sngmbh') && SASO_EVENTTICKETS::getRequestPara('a_sngmbh') == "premium"
1711 && $param_data != null && isset($param_data['c'])
1712 && $param_data['c'] == "requestSerialsForOrder") {
1713 // premium add btn on order details overwrite the false
1714 $create_tickets = true;
1715 } else {
1716 // add the day per ticket if needed before the ticket number is added
1717 $items = $order->get_items();
1718 foreach ( $items as $item_id => $item ) {
1719 $product_id = $item->get_product_id();
1720 if( $product_id ){
1721 $isTicket = get_post_meta($product_id, 'saso_eventtickets_is_ticket', true) == "yes";
1722 if ($isTicket) {
1723 $variation_id = $item->get_variation_id();
1724 if ($variation_id > 0) {
1725 // check ob diese variation vom ticket ausgeschlossen ist
1726 if (get_post_meta($variation_id, '_saso_eventtickets_is_not_ticket', true) == "yes") {
1727 continue;
1728 }
1729 }
1730
1731 // check if it is a daychooser
1732 $isDaychooser = get_post_meta($product_id, 'saso_eventtickets_is_daychooser', true) == "yes";
1733 if ($isDaychooser) {
1734 $days_per_ticket = [];
1735 $daychooser = wc_get_order_item_meta($item_id, 'saso_eventtickets_request_daychooser', true);
1736 if ($daychooser != null && is_array($daychooser) && count($daychooser) > 0) {
1737 $quantity = $item->get_quantity();
1738 for($a=0;$a<$quantity;$a++) {
1739 if (isset($daychooser[$a])) {
1740 $days_per_ticket = $daychooser[$a];
1741 }
1742 }
1743 wc_delete_order_item_meta( $item_id, "_saso_eventtickets_daychooser" );
1744 wc_add_order_item_meta($item_id , "_saso_eventtickets_daychooser", implode(",", $days_per_ticket) ) ;
1745 }
1746 }
1747 }
1748 }
1749 }
1750 }
1751 }
1752
1753 if ($create_tickets) {
1754 $items = $order->get_items();
1755 foreach ( $items as $item_id => $item ) {
1756 $product_id = $item->get_product_id();
1757 if( $product_id ){
1758 $isTicket = get_post_meta($product_id, 'saso_eventtickets_is_ticket', true) == "yes";
1759 if ($isTicket) {
1760 $variation_id = $item->get_variation_id();
1761 if ($variation_id > 0) {
1762 // check ob diese variation vom ticket ausgeschlossen ist
1763 if (get_post_meta($variation_id, '_saso_eventtickets_is_not_ticket', true) == "yes") {
1764 continue;
1765 }
1766 }
1767 $code_list_id = get_post_meta($product_id, 'saso_eventtickets_list', true);
1768 if (!empty($code_list_id)) {
1769 $this->add_serialcode_to_order_forItem($order_id, $order, $item_id, $item, $code_list_id, '_saso_eventtickets_product_code', '_saso_eventticket_code_list');
1770 }
1771 }
1772 }
1773 } // end foreach
1774 }
1775
1776 if (isset(WC()->session)) {
1777 $session_keys = ['saso_eventtickets_request_name_per_ticket', 'saso_eventtickets_request_value_per_ticket', 'saso_eventtickets_request_daychooser'];
1778 if (!WC()->session->has_session()) {
1779 if (method_exists(WC()->session, '__unset')) {
1780 foreach($session_keys as $k) {
1781 WC()->session->__unset($k);
1782 }
1783 } else {
1784 if (method_exists(WC()->session, '__isset')) {
1785 foreach($session_keys as $k) {
1786 if (WC()->session->__isset($k)) {
1787 WC()->session->set($k, []);
1788 }
1789 }
1790 }
1791 }
1792 }
1793 }
1794
1795 }
1796
1797 function add_serialcode_to_order_forItem($order_id, $order, $item_id, $item, $saso_eventtickets_list, $codeName, $codeListName) {
1798 $ret = [];
1799 $product_id = $item->get_product_id();
1800 if ($saso_eventtickets_list) {
1801
1802 if ($item->get_variation_id() > 0) {
1803 $saso_eventtickets_ticket_amount_per_item = intval(get_post_meta( $item->get_variation_id(), 'saso_eventtickets_ticket_amount_per_item', true ));
1804 } else {
1805 $saso_eventtickets_ticket_amount_per_item = intval(get_post_meta( $product_id, 'saso_eventtickets_ticket_amount_per_item', true ));
1806 }
1807 if ($saso_eventtickets_ticket_amount_per_item < 1) {
1808 $saso_eventtickets_ticket_amount_per_item = 1;
1809 }
1810
1811 $item_qty_refunded = $order->get_qty_refunded_for_item( $item_id );
1812 $quantity = $item->get_quantity() + $item_qty_refunded;
1813 $quantity *= $saso_eventtickets_ticket_amount_per_item;
1814
1815 $existingCode = wc_get_order_item_meta($item_id , $codeName, true);
1816 $codes = [];
1817 if (!empty($existingCode)) {
1818 $codes = explode(",", $existingCode);
1819 $quantity = $quantity - count($codes);
1820 }
1821
1822 if ($quantity > 0) {
1823
1824 $product_formatter_values = "";
1825 if (get_post_meta($product_id, 'saso_eventtickets_list_formatter', true) == "yes") {
1826 $product_formatter_values = get_post_meta( $product_id, 'saso_eventtickets_list_formatter_values', true );
1827 }
1828
1829 $values = [];
1830 $namesPerTicket = wc_get_order_item_meta($item_id, 'saso_eventtickets_request_name_per_ticket', true);
1831 if ($namesPerTicket != null && is_array($namesPerTicket) && count($namesPerTicket) > 0) {
1832 $values = $namesPerTicket;
1833 }
1834 $values2 = [];
1835 $valuesPerTicket = wc_get_order_item_meta($item_id, 'saso_eventtickets_request_value_per_ticket', true);
1836 if ($valuesPerTicket != null && is_array($valuesPerTicket) && count($valuesPerTicket) > 0) {
1837 $values2 = $valuesPerTicket;
1838 }
1839 $daychooser = [];
1840 $daysPerTicket = wc_get_order_item_meta($item_id, 'saso_eventtickets_request_daychooser', true);
1841 if ($daysPerTicket != null && is_array($daysPerTicket) && count($daysPerTicket) > 0) {
1842 $daychooser = $daysPerTicket;
1843 }
1844
1845 $public_ticket_ids_value = wc_get_order_item_meta($item_id , '_saso_eventtickets_public_ticket_ids', true);
1846 $public_ticket_ids = explode(",", $public_ticket_ids_value);
1847
1848 $new_codes = [];
1849 $days_per_ticket = [];
1850 $offset = count($codes);
1851 for($a=0;$a<$quantity;$a++) {
1852 $namePerTicket = "";
1853 if (isset($values[$offset + $a])) {
1854 $namePerTicket = $values[$offset + $a];
1855 }
1856 $valuePerTicket = "";
1857 if (isset($values2[$offset + $a])) {
1858 $valuePerTicket = $values2[$offset + $a];
1859 }
1860 $dayPerTicket = "";
1861 if (isset($daychooser[$offset + $a])) {
1862 $dayPerTicket = $daychooser[$offset + $a];
1863 }
1864 $newcode = "";
1865 try {
1866 $newcode = $this->getAdmin()->addCodeFromListForOrder($saso_eventtickets_list, $order_id, $product_id, $item_id, $product_formatter_values);
1867 } catch(Exception $e) {
1868 // error handling
1869 $order = wc_get_order( $order_id );
1870 $order->add_order_note(esc_html__("Free ticket numbers used up. Added placeholder", 'event-tickets-with-ticket-scanner'));
1871 // for now ignoring them
1872 }
1873 $codeObj = null;
1874 try {
1875 $codeObj = $this->getAdmin()->setWoocommerceTicketInfoForCode($newcode, $namePerTicket, $valuePerTicket, $dayPerTicket);
1876 } catch(Exception $e) {
1877 $this->getAdmin()->logErrorToDB($e, "", "while processing the order and storing the name-value per tickets. ".$newcode." - ".$namePerTicket." - ".$valuePerTicket);
1878 }
1879 if ($codeObj != null) {
1880 $metaObj = $this->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj);
1881 $public_ticket_ids[] = $metaObj['wc_ticket']['_public_ticket_id'];
1882 }
1883 $new_codes[] = $newcode;
1884 $days_per_ticket[] = $dayPerTicket;
1885 } // end for quantity
1886 $codes = array_merge($codes, $new_codes);
1887 if (count($codes) > 0) {
1888 $ret = $codes;
1889 wc_delete_order_item_meta( $item_id, $codeName );
1890 wc_add_order_item_meta($item_id , $codeName, implode(",", $codes) ) ;
1891 wc_delete_order_item_meta( $item_id, $codeListName );
1892 wc_add_order_item_meta($item_id , $codeListName, $saso_eventtickets_list ) ;
1893 wc_delete_order_item_meta( $item_id, "_saso_eventtickets_daychooser" );
1894 wc_add_order_item_meta($item_id , "_saso_eventtickets_daychooser", implode(",", $days_per_ticket) ) ;
1895 }
1896 if (count($public_ticket_ids) > 0) {
1897 wc_delete_order_item_meta( $item_id, "_saso_eventtickets_public_ticket_ids" );
1898 wc_add_order_item_meta($item_id , "_saso_eventtickets_public_ticket_ids", implode(",", $public_ticket_ids) ) ;
1899 }
1900
1901 wc_delete_order_item_meta( $item_id, '_saso_eventtickets_is_ticket' );
1902 wc_add_order_item_meta($item_id , '_saso_eventtickets_is_ticket', 1, true );
1903 }
1904 }
1905 return $ret;
1906 }
1907
1908 private function getAdmin() {
1909 return $this->MAIN->getAdmin();
1910 }
1911 private function getFrontend() {
1912 return $this->MAIN->getFrontend();
1913 }
1914 private function getCore() {
1915 return $this->MAIN->getCore();
1916 }
1917 private function getOptions() {
1918 return $this->MAIN->getOptions();
1919 }
1920
1921 private function downloadAllTicketsAsOnePDF($data, $filemode="I") {
1922 $order_id = intval($data['order_id']);
1923 if ($order_id > 0) {
1924 $order = wc_get_order( $order_id );
1925 $ticketHandler = $this->MAIN->getTicketHandler();
1926 $ticketHandler->outputPDFTicketsForOrder($order);
1927 exit;
1928 } else {
1929 echo "ORDER ID IS WRONG";
1930 exit;
1931 }
1932 }
1933
1934 private function removeAllTicketsFromOrder($data) {
1935 $order_id = intval($data['order_id']);
1936 if ($order_id > 0) {
1937 $this->removeTicketInfosFromOrder( $order_id );
1938 }
1939 return true;
1940 }
1941
1942 private function removeAllNonTicketsFromOrder($data) {
1943 $order_id = intval($data['order_id']);
1944 if ($order_id > 0) {
1945 $order = wc_get_order( $order_id );
1946 if ($order != null) {
1947 $items = $order->get_items();
1948 foreach ( $items as $item_id => $item ) {
1949 //$this->woocommerce_delete_order_item($item_id);
1950 $code_value = wc_get_order_item_meta($item_id , "_saso_eventtickets_product_code", true);
1951 $good_codes = [];
1952 if (!empty($code_value)) {
1953 $codes = explode(",", $code_value);
1954 foreach($codes as $code) {
1955 $code = trim($code);
1956 if (!empty($code)) {
1957 // check if ticket number exists in db, otherwise delete it
1958 try {
1959 $codeObj = $this->getCore()->retrieveCodeByCode($code);
1960 $good_codes[] = $code;
1961 } catch (Exception $e) {
1962 $order->add_order_note( sprintf(/* translators: %s: ticket number */esc_html__('Ticket placeholder removed for order item id: %s.', 'event-tickets-with-ticket-scanner'), esc_attr($item_id)) );
1963 }
1964 }
1965 }
1966 if (count($good_codes) != count($codes)) {
1967 wc_delete_order_item_meta( $item_id, '_saso_eventtickets_product_code' );
1968 wc_add_order_item_meta($item_id , "_saso_eventtickets_product_code", implode(",", $good_codes));
1969 }
1970 }
1971 }
1972 }
1973 }
1974 return true;
1975 }
1976
1977 private function downloadTicketInfosOfProduct($data) {
1978 $product_id = intval($data['product_id']);
1979 $product = [];
1980 if ($product_id > 0){
1981 $daten = $this->getAdmin()->getCodesByProductId($product_id);
1982 $productObj = wc_get_product( $product_id );
1983 if ($productObj != null) {
1984 $product['name'] = $productObj->get_name();
1985 }
1986 }
1987 return ['ticket_infos'=>$daten, 'product'=>$product];
1988 }
1989
1990 private function downloadICSFile($data) {
1991 $product_id = intval($data['product_id']);
1992 $this->MAIN->getTicketHandler()->sendICSFileByProductId($product_id);
1993 exit;
1994 }
1995
1996 private function downloadFlyer($data) {
1997 if (!isset($data['product_id'])) throw new Exception("#6001 ".esc_html__("Product Id for the event flyer is missing", 'event-tickets-with-ticket-scanner'));
1998 $product_id = intval($data['product_id']);
1999
2000 $pdf = $this->MAIN->getNewPDFObject();
2001
2002 // lade product
2003 $product = wc_get_product( $product_id );
2004 $titel = $product->get_name();
2005 $short_desc = $product->get_short_description();
2006 $location = trim(get_post_meta( $product_id, 'saso_eventtickets_event_location', true ));
2007
2008 $dateAsString = $this->MAIN->getTicketHandler()->displayTicketDateAsString($product);
2009 $event_date = "";
2010 if (!empty($dateAsString)) {
2011 $event_date = '<br><p style="text-align:center;">';
2012 $event_date .= $dateAsString;
2013 $event_date .= '</p>';
2014 }
2015
2016 $event_url = get_permalink( $product->get_id() );
2017
2018 $pdf->setFilemode('I');
2019
2020 $wcTicketFlyerBanner = $this->getOptions()->getOptionValue('wcTicketFlyerBanner');
2021 if (!empty($wcTicketFlyerBanner) && intval($wcTicketFlyerBanner) > 0) {
2022 $mediaData = SASO_EVENTTICKETS::getMediaData($wcTicketFlyerBanner);
2023 /*
2024 $option_wcTicketFlyerBanner = $this->getOptions()->getOption('wcTicketFlyerBanner');
2025 $width = "600";
2026 if (isset($option_wcTicketFlyerBanner['additional']) && isset($option_wcTicketFlyerBanner['additional']['min']) && isset($option_wcTicketFlyerBanner['additional']['min']['width'])) {
2027 $width = $option_wcTicketFlyerBanner['additional']['min']['width'];
2028 }*/
2029 $has_banner = false;
2030 if ($this->getOptions()->isOptionCheckboxActive('wcTicketCompatibilityUseURL')) {
2031 if (!empty($mediaData['url'])) {
2032 $pdf->addPart('<div style="text-align:center;"><img src="'.$mediaData['url'].'"></div>');
2033 $has_banner = true;
2034 }
2035 } else {
2036 if (!empty($mediaData['for_pdf'])) {
2037 $pdf->addPart('<div style="text-align:center;"><img src="'.$mediaData['for_pdf'].'"></div>');
2038 $has_banner = true;
2039 }
2040 }
2041 if ($has_banner) {
2042 if (isset($mediaData['meta']) && isset($mediaData['meta']['height']) && floatval($mediaData['meta']['height']) > 0) {
2043 $dpiY = 96;
2044 if (function_exists("getimagesize")) {
2045 $imageInfo = getimagesize($mediaData['location']);
2046 // DPI-Werte aus den EXIF-Daten extrahieren
2047 $dpiY = isset($imageInfo['dpi_y']) ? $imageInfo['dpi_y'] : $dpiY;
2048 }
2049 $units = $pdf->convertPixelIntoMm($mediaData['meta']['height'] + 10, $dpiY);
2050 $pdf->setQRParams(['pos'=>['y'=>$units]]);
2051 }
2052 }
2053 }
2054 $pdf->addPart('<h1 style="text-align:center;">'.esc_html($titel).'</h1>');
2055 if (!empty($event_date)) {
2056 $pdf->addPart($event_date);
2057 }
2058 if (!empty($location)) {
2059 $pdf->addPart('<p>'.wp_kses_post($this->getOptions()->getOptionValue("wcTicketTransLocation"))." <b>".wp_kses_post($location)."</b></p>");
2060 }
2061
2062 $pdf->addPart('{QRCODE_INLINE}');
2063 $pdf->addPart('<br><p style="font-size:9pt;text-align:center;">'.esc_url($event_url).'</p>');
2064 $pdf->addPart('<br><p style="text-align:center;">'.wp_kses_post($short_desc).'</p>');
2065 $wcTicketFlyerDontDisplayPrice = $this->getOptions()->isOptionCheckboxActive('wcTicketFlyerDontDisplayPrice');
2066 if (!$wcTicketFlyerDontDisplayPrice) {
2067 $pdf->addPart('<br><br><p style="text-align:center;font-size:18pt;">'.wc_price($product->get_price(), ['decimals'=>2]).'</p>');
2068 }
2069 $wcTicketFlyerDontDisplayBlogName = $this->getOptions()->isOptionCheckboxActive('wcTicketFlyerDontDisplayBlogName');
2070 if (!$wcTicketFlyerDontDisplayBlogName) {
2071 $pdf->addPart('<br><br><div style="text-align:center;font-size:10pt;"><b>'.get_bloginfo("name").'</b></div>');
2072 }
2073 $wcTicketFlyerDontDisplayBlogDesc = $this->getOptions()->isOptionCheckboxActive('wcTicketFlyerDontDisplayBlogDesc');
2074 if (!$wcTicketFlyerDontDisplayBlogDesc) {
2075 if ($wcTicketFlyerDontDisplayBlogName) $pdf->addPart('<br>');
2076 $pdf->addPart('<div style="text-align:center;font-size:10pt;">'.get_bloginfo("description").'</div>');
2077 }
2078 if (!$this->getOptions()->isOptionCheckboxActive('wcTicketFlyerDontDisplayBlogURL')) {
2079 $pdf->addPart('<br><div style="text-align:center;font-size:10pt;">'.site_url().'</div>');
2080 }
2081 $wcTicketFlyerLogo = $this->getOptions()->getOptionValue('wcTicketFlyerLogo');
2082 if (!empty($wcTicketFlyerLogo) && intval($wcTicketFlyerLogo) >0) {
2083 $option_wcTicketFlyerLogo = $this->getOptions()->getOption('wcTicketFlyerLogo');
2084 $mediaData = SASO_EVENTTICKETS::getMediaData($wcTicketFlyerLogo);
2085 $width = "200";
2086 if (isset($option_wcTicketFlyerLogo['additional']) && isset($option_wcTicketFlyerLogo['additional']['max']) && isset($option_wcTicketFlyerLogo['additional']['max']['width'])) {
2087 $width = $option_wcTicketFlyerLogo['additional']['max']['width'];
2088 }
2089
2090 if ($this->getOptions()->isOptionCheckboxActive('wcTicketCompatibilityUseURL')) {
2091 if (!empty($mediaData['url'])) {
2092 $pdf->addPart('<br><br><p style="text-align:center;"><img width="'.$width.'" src="'.$mediaData['url'].'"></p>');
2093 }
2094 } else {
2095 if (!empty($mediaData['for_pdf'])) {
2096 $pdf->addPart('<br><br><p style="text-align:center;"><img width="'.$width.'" src="'.$mediaData['for_pdf'].'"></p>');
2097 }
2098 }
2099 }
2100 $pdf->addPart('<br><p style="text-align:center;font-size:9pt;">powered by Event Tickets With Ticket Scanner Plugin for Wordpress</p>');
2101
2102 //$pdf->setQRParams(['style'=>['position'=>'C']]);
2103 $pdf->setQRParams(['style'=>['position'=>'C'],'align'=>'N']);
2104 $qrTicketPDFPadding = intval($this->getOptions()->getOptionValue('qrTicketPDFPadding'));
2105 $pdf->setQRCodeContent(["text"=>$event_url, "style"=>["vpadding"=>$qrTicketPDFPadding, "hpadding"=>$qrTicketPDFPadding]]);
2106 $wcTicketFlyerBG = $this->getOptions()->getOptionValue('wcTicketFlyerBG');
2107 if (!empty($wcTicketFlyerBG) && intval($wcTicketFlyerBG) >0) {
2108 $mediaData = SASO_EVENTTICKETS::getMediaData($wcTicketFlyerBG);
2109 if ($this->getOptions()->isOptionCheckboxActive('wcTicketCompatibilityUseURL')) {
2110 if (!empty($mediaData['url'])) {
2111 $pdf->setBackgroundImage($mediaData['url']);
2112 }
2113 } else {
2114 if (!empty($mediaData['for_pdf'])) {
2115 $pdf->setBackgroundImage($mediaData['for_pdf']);
2116 }
2117 }
2118 }
2119 $pdf->render();
2120 exit;
2121 }
2122
2123 private function containsProductsWithRestrictions() {
2124 if ($this->_containsProductsWithRestrictions == null) {
2125 $this->_containsProductsWithRestrictions = false;
2126 // loop through cart items and check if a restriction is set
2127 foreach(WC()->cart->get_cart() as $cart_item ) {
2128 // Check cart item for defined product Ids and applied coupon
2129 $saso_eventtickets_list = get_post_meta($cart_item['product_id'], $this->meta_key_codelist_restriction, true);
2130
2131 if (!empty($saso_eventtickets_list)) {
2132 $this->_containsProductsWithRestrictions = true;
2133 break;
2134 }
2135 }
2136 }
2137 return $this->_containsProductsWithRestrictions;
2138 }
2139
2140 function woocommerce_review_order_after_cart_contents() {
2141 if ($this->getOptions()->isOptionCheckboxActive('wcTicketShowInputFieldsOnCheckoutPage')) {
2142 // load wc_frontend.js to the checkout view
2143 if ( ! is_ajax() ) { // prevent rendering for ajax call
2144 $this->addJSFileAndHandler();
2145 // render the input fields.
2146 $cart_items = WC()->cart->get_cart();
2147 foreach($cart_items as $cart_item_key => $cart_item) {
2148 $this->woocommerce_after_cart_item_name( $cart_item, $cart_item_key );
2149 }
2150 }
2151 echo '<p class="sasoEventtickets_cart_spacer_bottom">&nbsp;</p>';
2152 }
2153 }
2154 // add all filter and actions, if we are displaying the cart, checkout and have products with restrictions
2155 function woocommerce_before_cart_table() {
2156 add_action( 'woocommerce_after_cart_item_name', [$this, 'woocommerce_after_cart_item_name'], 10, 2 );
2157 $added = false;
2158 if ($this->getOptions()->isOptionCheckboxActive('wcRestrictPurchase')) { // not in use anymore. But maybe with old installations
2159 if ($this->containsProductsWithRestrictions()) {
2160 $this->addJSFileAndHandler();
2161 $added = true;
2162 }
2163 }
2164 if ($this->hasTicketsInCart() && $added == false) {
2165 $this->addJSFileAndHandler();
2166 }
2167 }
2168
2169 private function addJSFileAndHandler() {
2170 // erstmal ist diese fkt nur für sales restriction
2171 if (version_compare( WC_VERSION, SASO_EVENTTICKETS_PLUGIN_MIN_WC_VER, '<' )) return;
2172
2173 wp_register_style( 'jquery-ui', 'https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css' );
2174 wp_enqueue_style( 'jquery-ui' );
2175 wp_enqueue_style("wp-jquery-ui-dialog");
2176 wp_enqueue_style("wp-jquery-ui-datepicker");
2177 wp_enqueue_style("jquery-ui");
2178 wp_enqueue_style("jquery-ui-datepicker");
2179 wp_register_script(
2180 'SasoEventticketsValidator_WC_frontend',
2181 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'wc_frontend.js?_v='.$this->MAIN->getPluginVersion(),
2182 array( 'jquery', 'jquery-ui-dialog', 'jquery-blockui', 'jquery-ui-datepicker', 'wp-i18n' ),
2183 (current_user_can("administrator") ? current_time("timestamp") : $this->MAIN->getPluginVersion()),
2184 true );
2185 wp_set_script_translations('SasoEventticketsValidator_WC_frontend', 'event-tickets-with-ticket-scanner', __DIR__.'/languages');
2186 wp_localize_script(
2187 'SasoEventticketsValidator_WC_frontend',
2188 'SasoEventticketsValidator_phpObject', // name der js variable
2189 [
2190 'ajaxurl' => admin_url( 'admin-ajax.php' ),
2191 'inputType' => $this->js_inputType,
2192 'action' => $this->getPrefix().'_executeWCFrontend',
2193 'nonce' => wp_create_nonce( $this->MAIN->_js_nonce ),
2194 ] // werte in der js variable
2195 );
2196 wp_enqueue_script('SasoEventticketsValidator_WC_frontend');
2197 }
2198
2199 public function executeWCFrontend() {
2200 // not anymore just for restrict purchase
2201 //if ($this->getOptions()->isOptionCheckboxActive('wcRestrictPurchase')) { // not in use anymore. But maybe with old installations
2202 // Do a nonce check
2203 //$nonce_mode = 'woocommerce-cart';
2204 $nonce_mode = $this->MAIN->_js_nonce;
2205 if( ! SASO_EVENTTICKETS::issetRPara('security') || ! wp_verify_nonce(SASO_EVENTTICKETS::getRequestPara('security'), $nonce_mode) ) {
2206 wp_send_json( ['nonce_fail' => 1] );
2207 exit;
2208 }
2209 if (!SASO_EVENTTICKETS::issetRPara('a')) return wp_send_json_error("a not provided");
2210
2211 $ret = "";
2212 $justJSON = false;
2213 $a = trim(SASO_EVENTTICKETS::getRequestPara('a'));
2214 try {
2215 switch ($a) {
2216 case "updateSerialCodeToCartItem":
2217 $ret = $this->wc_frontend_updateSerialCodeToCartItem();
2218 break;
2219 case "updateSerialCodeToCartItemRestriction": // not used and not implemented in wc_frontend.js
2220 $ret = $this->wc_frontend_updateSerialCodeToCartItemRestriction();
2221 break;
2222 default:
2223 throw new Exception("#6003 ".sprintf(/* translators: %s: name of called function */esc_html__('function "%s" not implemented', 'event-tickets-with-ticket-scanner'), $a));
2224 }
2225 } catch(Exception $e) {
2226 $this->MAIN->getAdmin()->logErrorToDB($e);
2227 return wp_send_json_error (['msg'=>$e->getMessage()]);
2228 }
2229 if ($justJSON) return wp_send_json($ret);
2230 else return wp_send_json_success( $ret );
2231 //}
2232 }
2233
2234 private function wc_frontend_updateSerialCodeToCartItem() {
2235 // Save the code to the cart meta
2236 $cart_item_id = sanitize_key(SASO_EVENTTICKETS::getRequestPara('cart_item_id'));
2237 $cart_item_count = intval(SASO_EVENTTICKETS::getRequestPara('cart_item_count'));
2238 $k = sanitize_key(SASO_EVENTTICKETS::getRequestPara('type'));
2239 if (!in_array($k, [
2240 'saso_eventtickets_request_name_per_ticket',
2241 'saso_eventtickets_request_value_per_ticket',
2242 'saso_eventtickets_request_daychooser'
2243 ])) {
2244 $k = 'saso_eventtickets_request_name_per_ticket';
2245 }
2246 $code = trim(SASO_EVENTTICKETS::getRequestPara('code')); // is any value that was send to this function
2247
2248 $check_values = [];
2249 if (empty($cart_item_id)) {
2250 $check_values["item_id_missing"] = true;
2251 } else {
2252 $valueArray = WC()->session->get($k);
2253 if ($valueArray == null) {
2254 $valueArray = [];
2255 }
2256 if (!isset($valueArray[$cart_item_id]) || !is_array($valueArray[$cart_item_id])) {
2257 $valueArray[$cart_item_id] = [];
2258 }
2259 $valueArray[$cart_item_id][$cart_item_count] = $code;
2260 WC()->session->set($k, $valueArray);
2261 }
2262
2263 wp_send_json( ['success' => 1, 'code'=>esc_attr($code), 'check_values'=>$check_values, 'type'=>$k] );
2264 exit;
2265 }
2266
2267 private function wc_frontend_updateSerialCodeToCartItemRestriction() {
2268 // Save the code to the cart meta
2269 $cart = WC()->cart->cart_contents;
2270 $cart_item_id = sanitize_key(SASO_EVENTTICKETS::getRequestPara('cart_item_id'));
2271 $code = sanitize_key(SASO_EVENTTICKETS::getRequestPara('code'));
2272 $code = strtoupper($code);
2273
2274 $check_values = [];
2275 if (empty($cart_item_id)) {
2276 $check_values["item_id_missing"] = true;
2277 } else {
2278 $cart_item = $cart[$cart_item_id];
2279
2280 $cart_item[$this->meta_key_codelist_restriction_order_item] = $code;
2281
2282 WC()->cart->cart_contents[$cart_item_id] = $cart_item;
2283 WC()->cart->set_session();
2284
2285 switch($this->check_code_for_cartitem($cart_item, $code)) {
2286 case 0:
2287 $check_values['isEmpty'] = true;
2288 break;
2289 case 1:
2290 $check_values['isValid'] = true;
2291 break;
2292 case 2:
2293 $check_values['isUsed'] = true;
2294 break;
2295 case 3: // not valid
2296 case 4: // no code list
2297 default:
2298 $check_values['notValid'] = true;
2299 }
2300 }
2301
2302 wp_send_json( ['success' => 1, 'code'=>esc_attr(strtoupper($code)), 'check_values'=>$check_values] );
2303 exit;
2304 }
2305
2306 // speicher custom field aus dem cart - wird auch aufgerufen, wenn man den warenkorb aufruft und warenkorb updates macht
2307 function woocommerce_cart_updated( ) {
2308 $R = SASO_EVENTTICKETS::getRequest();
2309 if (isset($R["action"]) && strtolower($R["action"]) == "heartbeat") {
2310 return;
2311 }
2312 $session_keys = ['saso_eventtickets_request_name_per_ticket', 'saso_eventtickets_request_value_per_ticket', 'saso_eventtickets_request_daychooser'];
2313 $cart = null;
2314 foreach($session_keys as $k) {
2315 if ( isset( $R[$k] ) ) { // wenn der warenkorb aktualisiert wird und das feld gesendet wird
2316 $values = [];
2317 if ($cart == null) {
2318 $cart = WC()->cart;
2319 }
2320 foreach( $cart->get_cart() as $cart_item ) {
2321 if (isset($R[$k][$cart_item['key']])) {
2322 $value = $R[$k][$cart_item['key']];
2323 $values[$cart_item['key']] = $value;
2324 }
2325 }
2326 if (count($values) > 0) {
2327 WC()->session->set($k, $values);
2328 } else {
2329 WC()->session->__unset($k);
2330 }
2331 }
2332 }
2333 }
2334
2335 // zeige eingabe maske für das Produkt, wenn es eine purchase restriction mit codes hat
2336 function woocommerce_after_cart_item_name( $cart_item, $cart_item_key ) {
2337 $saso_eventtickets_list = get_post_meta($cart_item['product_id'], $this->meta_key_codelist_restriction, true);
2338 if (!empty($saso_eventtickets_list)) {
2339 $code = isset( $cart_item[$this->meta_key_codelist_restriction_order_item] ) ? $cart_item[$this->meta_key_codelist_restriction_order_item] : '';
2340 $infoLabel = $this->getOptions()->getOptionValue('wcRestrictCartInfo');
2341 $fieldPlaceholder = $this->getOptions()->getOptionValue('wcRestrictCartFieldPlaceholder');
2342 $html = '<div><small>'.esc_attr($infoLabel).'<br></small>
2343 <input
2344 type="text"
2345 maxlength="140"
2346 placeholder="%s"
2347 data-input-type="%s"
2348 data-cart-item-id="%s"
2349 data-plugin="event"
2350 value="%s"
2351 class="input-text text" /></div>';
2352 printf(
2353 str_replace("\n", "", $html),
2354 esc_attr($fieldPlaceholder),
2355 esc_attr($this->js_inputType),
2356 esc_attr($cart_item_key),
2357 wc_clean($code)
2358 );
2359 }
2360
2361 // check if the product is a daychooser
2362 $saso_eventtickets_is_daychooser = get_post_meta($cart_item['product_id'], "saso_eventtickets_is_daychooser", true) == "yes";
2363 // render the datepicker
2364 if ($saso_eventtickets_is_daychooser) {
2365 $anzahl = intval($cart_item["quantity"]);
2366 if ($anzahl > 0) {
2367 $valueArray = WC()->session->get("saso_eventtickets_request_daychooser");
2368
2369 $product_id = $cart_item['product_id'];
2370 $dates = $this->MAIN->getTicketHandler()->getCalcDateStringAllowedRedeemFromCorrectProduct($product_id);
2371 $saso_eventtickets_daychooser_offset_start = $dates['daychooser_offset_start'];
2372 $saso_eventtickets_daychooser_offset_end = $dates['daychooser_offset_end'];
2373 $saso_eventtickets_daychooser_exclude_wdays = $dates['daychooser_exclude_wdays'];
2374 $saso_eventtickets_ticket_start_date = $dates['ticket_start_date'];
2375 $saso_eventtickets_ticket_end_date = $dates['ticket_end_date'];
2376
2377 if (!is_array($saso_eventtickets_daychooser_exclude_wdays)) {
2378 $saso_eventtickets_daychooser_exclude_wdays = [];
2379 }
2380
2381 $label = esc_attr($this->MAIN->getTicketHandler()->getLabelDaychooserPerTicket($cart_item['product_id']));
2382 for ($a=0;$a<$anzahl;$a++) {
2383 $value = "";
2384 if ($valueArray != null && isset($valueArray[$cart_item_key]) && isset($valueArray[$cart_item_key][$a])) {
2385 $value = trim($valueArray[$cart_item_key][$a]);
2386 }
2387
2388 $params = [
2389 'type' => 'text',
2390 'custom_attributes' => [
2391 'data-input-type'=>'daychooser',
2392 'data-plugin'=>'event',
2393 'data-cart-item-id'=>$cart_item_key,
2394 'data-cart-item-count'=>$a,
2395 //'disabled'=>true,
2396 'style'=>'width:auto;'
2397 ],
2398 'id'=>'saso_eventtickets_request_daychooser['.$cart_item_key.']['.$a.']',
2399 'class'=> array( 'form-row-first input-text text' ),
2400 'label' => esc_attr(str_replace("{count}", $a+1, $label)),
2401 'required' => true, // Or false
2402 ];
2403 $params['custom_attributes']['data-offset-start'] = $saso_eventtickets_daychooser_offset_start;
2404 $params['custom_attributes']['data-offset-end'] = $saso_eventtickets_daychooser_offset_end;
2405 $params['custom_attributes']['data-exclude-wdays'] = implode(",", $saso_eventtickets_daychooser_exclude_wdays);
2406
2407 if ($this->MAIN->isPremium() && method_exists($this->MAIN->getPremiumFunctions(), 'getDayChooserExclusionDates')) {
2408 $exclusionDates = $this->MAIN->getPremiumFunctions()->getDayChooserExclusionDates($product_id);
2409 if (!empty($exclusionDates)) {
2410 $params['custom_attributes']['data-exclude-dates'] = implode(",", $exclusionDates);
2411 }
2412 }
2413
2414 if ($saso_eventtickets_ticket_start_date != "") {
2415 $params['custom_attributes']['min'] = $saso_eventtickets_ticket_start_date;
2416 }
2417 if ($saso_eventtickets_daychooser_offset_start > 0) {
2418 // if the start date is not set, then we set it to the start today + days offset
2419 if (!isset($params['custom_attributes']['min'])) {
2420 $params['custom_attributes']['min'] = date("Y-m-d", strtotime("+".$saso_eventtickets_daychooser_offset_start." days"));
2421 } else {
2422 // if the start date + offset days is set before the ticket start date then use the start date
2423 if (current_time("timestamp") < strtotime($params['custom_attributes']['min']." -".$saso_eventtickets_daychooser_offset_start." days")) {
2424 $params['custom_attributes']['min'] = $saso_eventtickets_ticket_start_date;
2425 } else {
2426 $params['custom_attributes']['min'] = date("Y-m-d", strtotime("+".$saso_eventtickets_daychooser_offset_start." days"));
2427 }
2428 }
2429 }
2430 if ($saso_eventtickets_ticket_end_date != "") {
2431 $params['custom_attributes']['max'] = $saso_eventtickets_ticket_end_date;
2432 }
2433 if (!isset($params['custom_attributes']['max']) && $saso_eventtickets_daychooser_offset_end > 0) {
2434 $params['custom_attributes']['max'] = date("Y-m-d", strtotime("+".$saso_eventtickets_daychooser_offset_end." days"));
2435 }
2436
2437 echo '<div id="datepicker-wrapper_'.$cart_item_key.'_'.$a.'">';
2438 woocommerce_form_field('saso_eventtickets_request_daychooser['.$cart_item_key.'][]', $params, $value );
2439 echo '<br clear="all"></div>';
2440 }
2441 }
2442 }
2443
2444
2445 $saso_eventtickets_request_name_per_ticket = get_post_meta($cart_item['product_id'], "saso_eventtickets_request_name_per_ticket", true) == "yes";
2446 if ($saso_eventtickets_request_name_per_ticket) {
2447 $anzahl = intval($cart_item["quantity"]);
2448 if ($anzahl > 0) {
2449 $valueArray = WC()->session->get("saso_eventtickets_request_name_per_ticket");
2450
2451 $label = esc_attr($this->MAIN->getTicketHandler()->getLabelNamePerTicket($cart_item['product_id']));
2452 for ($a=0;$a<$anzahl;$a++) {
2453 $value = "";
2454 if ($valueArray != null && isset($valueArray[$cart_item_key]) && isset($valueArray[$cart_item_key][$a])) {
2455 $value = trim($valueArray[$cart_item_key][$a]);
2456 }
2457 $html = '<div class="saso_eventtickets_request_name_per_ticket_label"><small>'.str_replace("{count}", $a+1, $label).'<br></small>
2458 <input type="text" data-input-type="text"
2459 name="saso_eventtickets_request_name_per_ticket[%s][]"
2460 data-cart-item-id="%s"
2461 data-cart-item-count="%s"
2462 data-plugin="event"
2463 value="%s"
2464 class="input-text text" /></div>';
2465 printf(
2466 str_replace("\n", "", $html),
2467 esc_attr($cart_item_key),
2468 esc_attr($cart_item_key),
2469 esc_attr($a),
2470 esc_attr($value)
2471 );
2472 }
2473 }
2474 }
2475 $saso_eventtickets_request_value_per_ticket = get_post_meta($cart_item['product_id'], "saso_eventtickets_request_value_per_ticket", true) == "yes";
2476 if ($saso_eventtickets_request_value_per_ticket) {
2477 $anzahl = intval($cart_item["quantity"]);
2478 if ($anzahl > 0) {
2479 $valueArray = WC()->session->get("saso_eventtickets_request_value_per_ticket");
2480
2481 $dropdown_values = get_post_meta($cart_item['product_id'], "saso_eventtickets_request_value_per_ticket_values", true);
2482 $dropdown_def = get_post_meta($cart_item['product_id'], "saso_eventtickets_request_value_per_ticket_def", true);
2483 if (!empty($dropdown_values)) {
2484 $is_mandatory = get_post_meta($cart_item['product_id'], "saso_eventtickets_request_value_per_ticket_mandatory", true) == "yes";
2485 $label_option = esc_attr($this->MAIN->getTicketHandler()->getLabelValuePerTicket($cart_item['product_id']));
2486 for ($a=0;$a<$anzahl;$a++) {
2487 $value = "";
2488 if ($valueArray != null && isset($valueArray[$cart_item_key]) && isset($valueArray[$cart_item_key][$a])) {
2489 $value = trim($valueArray[$cart_item_key][$a]);
2490 }
2491 $l = str_replace("{count}", $a+1, $label_option);
2492 $html_options = "";
2493 $has_empty_option = false;
2494 foreach(explode("\n", $dropdown_values) as $entry) {
2495 $t = explode("|", $entry);
2496 $v = "";
2497 $label = "";
2498 if (count($t) > 0) {
2499 $v = sanitize_key(trim($t[0]));
2500 if (count($t) > 1) {
2501 $label = sanitize_key(trim($t[1]));
2502 }
2503 }
2504 if (!empty($v)){
2505 if (empty($label)) {
2506 $label = $v;
2507 }
2508 $html_options .= '<option value="'.esc_attr($v).'"';
2509 if ($value == $v || (empty($value) && $v == $dropdown_def)) {
2510 $html_options .= ' selected';
2511 }
2512 $html_options .= '>'.esc_html($label).'</option>';
2513 } else if (!empty($label)) {
2514 $html_options .= '<option>'.esc_html($label).'</option>';
2515 $has_empty_option = true;
2516 }
2517 }
2518 if ($is_mandatory && $has_empty_option == false) {
2519 $html_options = '<option>'.esc_html($l).'</option>'.$html_options;
2520 }
2521
2522 $html = '<div class="saso_eventtickets_request_value_per_ticket_label"><small>'.$l.'<br></small>
2523 <select
2524 name="saso_eventtickets_request_value_per_ticket[%s][]"
2525 data-input-type="value"
2526 data-cart-item-id="%s"
2527 data-cart-item-count="%s"
2528 data-plugin="event"
2529 class="dropdown">'.$html_options.'</select></div>';
2530 printf(
2531 str_replace("\n", "", $html),
2532 esc_attr($cart_item_key),
2533 esc_attr($cart_item_key),
2534 esc_attr($a)
2535 );
2536 }
2537 }
2538 }
2539 }
2540 }
2541
2542 private function check_code_for_cartitem($cart_item, $code) {
2543 $ret = 0; // empty
2544 if (!empty($code)) {
2545 // Check cart item for defined product Ids and applied coupon
2546 $saso_eventtickets_list_id = get_post_meta($cart_item['product_id'], $this->meta_key_codelist_restriction, true);
2547 if (!empty($saso_eventtickets_list_id)) {
2548 try {
2549 $codeObj = $this->getCore()->retrieveCodeByCode($code);
2550 if ($codeObj['aktiv'] != 1) throw new Exception("#6004 ticket number is not valid");
2551 if ($saso_eventtickets_list_id != "0" && $codeObj['list_id'] != $saso_eventtickets_list_id) throw new Exception("#6005 ticket is from wrong list");
2552 if ($this->getFrontend()->isUsed($codeObj)) {
2553 return 2; // isUsed
2554 } else {
2555 return 1; // ok
2556 }
2557 } catch(Exception $e) {
2558 return 3; // notValid
2559 }
2560 } else {
2561 return 4; // code has no code list -> notValid
2562 }
2563 }
2564 return $ret;
2565 }
2566
2567 private function check_cart_item_and_add_warnings() {
2568 $cart_items = WC()->cart->get_cart();
2569 if ($this->containsProductsWithRestrictions()) {
2570 // loop through cart items and check if a restriction is set
2571 foreach($cart_items as $item_id => $cart_item ) {
2572 $code = isset( $cart_item[$this->meta_key_codelist_restriction_order_item] ) ? $cart_item[$this->meta_key_codelist_restriction_order_item] : '';
2573 $code = strtoupper($code);
2574 switch($this->check_code_for_cartitem($cart_item, $code)) {
2575 case 0:
2576 wc_add_notice( sprintf(/* translators: %s: name of product */ __('The product "%s" requires a restriction code for checkout.', 'event-tickets-with-ticket-scanner'), esc_html($cart_item['data']->get_name()) ), 'error', ["cart-item-id"=>$item_id] );
2577 break;
2578 case 1: // valid
2579 break;
2580 case 2:
2581 wc_add_notice( sprintf(/* translators: 1: restriction code number 2: name of product */ __('The restriction code "%1$s" for product "%2$s" is already used.', 'event-tickets-with-ticket-scanner'), esc_attr($code), esc_html($cart_item['data']->get_name()) ), 'error', ["cart-item-id"=>$item_id] );
2582 break;
2583 case 3: // not valid
2584 case 4: // no code list
2585 default:
2586 wc_add_notice( sprintf(/* translators: 1: restriction code number 2: name of product */ __('The restriction code "%1$s" for product "%2$s" is not valid.', 'event-tickets-with-ticket-scanner'), esc_attr($code), esc_html($cart_item['data']->get_name()) ), 'error', ["cart-item-id"=>$item_id] );
2587 }
2588
2589 } // end loop cart item
2590 } // end if containsProductsWithRestrictions
2591
2592 // check if ticket name and dropdown value is needed and mandatory
2593 $valueArray = WC()->session->get("saso_eventtickets_request_name_per_ticket");
2594 foreach($cart_items as $item_id => $cart_item ) {
2595 $saso_eventtickets_request_name_per_ticket = get_post_meta($cart_item['product_id'], "saso_eventtickets_request_name_per_ticket", true) == "yes";
2596 if ($saso_eventtickets_request_name_per_ticket) {
2597 $saso_eventtickets_request_name_per_ticket_mandatory = get_post_meta($cart_item['product_id'], "saso_eventtickets_request_name_per_ticket_mandatory", true) == "yes";
2598 if ($saso_eventtickets_request_name_per_ticket_mandatory) {
2599 $anzahl = intval($cart_item["quantity"]);
2600 if ($anzahl > 0) {
2601 for ($a=0;$a<$anzahl;$a++) {
2602 $value = "";
2603 if ($valueArray != null && isset($valueArray[$cart_item['key']]) && isset($valueArray[$cart_item['key']][$a])) {
2604 $value = trim($valueArray[$cart_item['key']][$a]);
2605 }
2606 if (empty($value)) {
2607 $label = $this->getOptions()->getOptionValue('wcTicketLabelCartForName');
2608 $label = str_replace("{PRODUCT_NAME}", "%s", $label);
2609 //wc_add_notice( sprintf(/* translators: %s: name of product */ __('The product "%s" requires a value for checkout.', 'event-tickets-with-ticket-scanner'), esc_html($cart_item['data']->get_name()) ), 'error' );
2610 wc_add_notice( wp_kses_post(sprintf($label, esc_html($cart_item['data']->get_name())) ), 'error', ["cart-item-id"=>$item_id, ""] );
2611 break;
2612 }
2613 }
2614 }
2615 }
2616 }
2617 }
2618 $valueArray = WC()->session->get("saso_eventtickets_request_value_per_ticket");
2619 foreach($cart_items as $item_id => $cart_item ) {
2620 $saso_eventtickets_request_value_per_ticket = get_post_meta($cart_item['product_id'], "saso_eventtickets_request_value_per_ticket", true) == "yes";
2621 if ($saso_eventtickets_request_value_per_ticket) {
2622 $saso_eventtickets_request_value_per_ticket_mandatory = get_post_meta($cart_item['product_id'], "saso_eventtickets_request_value_per_ticket_mandatory", true) == "yes";
2623 if ($saso_eventtickets_request_value_per_ticket_mandatory) {
2624 $anzahl = intval($cart_item["quantity"]);
2625 if ($anzahl > 0) {
2626 for ($a=0;$a<$anzahl;$a++) {
2627 $value = "";
2628 if ($valueArray != null && isset($valueArray[$cart_item['key']]) && isset($valueArray[$cart_item['key']][$a])) {
2629 $value = trim($valueArray[$cart_item['key']][$a]);
2630 }
2631 if (empty($value)) {
2632 $label = $this->getOptions()->getOptionValue('wcTicketLabelCartForValue');
2633 $label = str_replace("{PRODUCT_NAME}", "%s", $label);
2634 //wc_add_notice( sprintf(/* translators: %s: name of product */ __('The product "%s" requires a value from the dropdown for checkout.', 'event-tickets-with-ticket-scanner'), esc_html($cart_item['data']->get_name()) ), 'error' );
2635 wc_add_notice( wp_kses_post(sprintf($label, esc_html($cart_item['data']->get_name())) ), 'error', ["cart-item-id"=>$item_id, "cart-item-count"=>$a] );
2636 break;
2637 }
2638 }
2639 }
2640 }
2641 }
2642 }
2643
2644 $valueArray = WC()->session->get("saso_eventtickets_request_daychooser");
2645 foreach($cart_items as $item_id => $cart_item ) {
2646 $saso_eventtickets_is_daychooser = get_post_meta($cart_item['product_id'], "saso_eventtickets_is_daychooser", true) == "yes";
2647 if ($saso_eventtickets_is_daychooser) {
2648 $anzahl = intval($cart_item["quantity"]);
2649 if ($anzahl > 0) {
2650 for ($a=0;$a<$anzahl;$a++) {
2651 $value = "";
2652 if ($valueArray != null && isset($valueArray[$cart_item['key']]) && isset($valueArray[$cart_item['key']][$a])) {
2653 $value = trim($valueArray[$cart_item['key']][$a]);
2654 }
2655 if (empty($value)) {
2656 $label = $this->getOptions()->getOptionValue('wcTicketLabelCartForDaychooser');
2657 $label = str_replace("{PRODUCT_NAME}", "%s", $label);
2658 $label = str_replace("{count}", "%d", $label);
2659 wc_add_notice( wp_kses_post(sprintf($label, esc_html($cart_item['data']->get_name()), $a+1) ), 'error', ["cart-item-id"=>$item_id, "cart-item-count"=>$a] );
2660 //break;
2661 } else {
2662 // test if the date is a date
2663 $date = DateTime::createFromFormat('Y-m-d', $value);
2664 if (!$date || $date->format('Y-m-d') !== $value) {
2665 $label = $this->getOptions()->getOptionValue('wcTicketLabelCartForDaychooserInvalidDate');
2666 $label = str_replace("{PRODUCT_NAME}", "%s", $label);
2667 $label = str_replace("{count}", "%d", $label);
2668 wc_add_notice(wp_kses_post(sprintf($label, esc_html($cart_item['data']->get_name()), $a+1)), 'error', ["cart-item-id"=>$item_id, "cart-item-count"=>$a]);
2669 //break;
2670 }
2671 }
2672 }
2673 }
2674 }
2675 }
2676 }
2677
2678 function woocommerce_checkout_process() {
2679 $this->check_cart_item_and_add_warnings();
2680 }
2681 function woocommerce_check_cart_items() {
2682 // check option wcTicketShowInputFieldsOnCheckoutPage if the check should be executed on the cart page
2683 if ($this->getOptions()->isOptionCheckboxActive('wcTicketShowInputFieldsOnCheckoutPage')) {
2684 /*
2685 $is_checkout = is_checkout();
2686 $is_cart = is_cart();
2687 if ($is_cart == true) {
2688 return "";
2689 }
2690 if ($is_checkout == true) {
2691 return "";
2692 }
2693 */
2694 } else {
2695 $this->check_cart_item_and_add_warnings();
2696 }
2697 }
2698
2699 private function setTicketValuesToOrderItem($item, $cart_item_key) {
2700 if (WC() != null && WC()->session != null) {
2701 $session_keys = ['saso_eventtickets_request_name_per_ticket', 'saso_eventtickets_request_value_per_ticket', 'saso_eventtickets_request_daychooser'];
2702 foreach($session_keys as $k) {
2703 $valueArray = WC()->session->get($k);
2704 if ($valueArray != null && isset($valueArray[$cart_item_key]) && isset($valueArray[$cart_item_key])) {
2705 $value = $valueArray[$cart_item_key];
2706 $item->update_meta_data($k, $value);
2707 }
2708 }
2709 }
2710 }
2711
2712 //The next step is to save the data to the order when it is processed to be paid
2713 function woocommerce_checkout_create_order_line_item( $item, $cart_item_key, $values, $order ) {
2714
2715 $this->setTicketValuesToOrderItem($item, $cart_item_key);
2716
2717 if ( empty( $values[$this->meta_key_codelist_restriction_order_item] ) ) {
2718 return;
2719 }
2720
2721 // speicher purchase restriction code zum order_item
2722 $code = $values[$this->meta_key_codelist_restriction_order_item];
2723 $item->add_meta_data( $this->meta_key_codelist_restriction_order_item, $code );
2724
2725 $codeObj = null;
2726 try {
2727 $codeObj = $this->getCore()->retrieveCodeByCode($code);
2728 } catch(Exception $e) {
2729 if(isset($_GET['VollstartValidatorDebug'])) {
2730 var_dump($e);
2731 }
2732 $this->MAIN->getAdmin()->logErrorToDB($e);
2733 }
2734
2735 // set as used
2736 if ($this->getOptions()->isOptionCheckboxActive('oneTimeUseOfRegisterCode')) {
2737 try {
2738 if ($codeObj == null) {
2739 $codeObj = $this->getCore()->retrieveCodeByCode($code);
2740 }
2741 $rc_v = $this->getOptions()->getOptionValue('wcRestrictOneTimeUsage');
2742 if ($rc_v == 1) {
2743 $codeObj = $this->getFrontend()->markAsUsed($codeObj);
2744 } else if ($rc_v == 2) {
2745 $codeObj = $this->getFrontend()->markAsUsed($codeObj, true);
2746 }
2747 } catch(Exception $e){
2748 if(isset($_GET['VollstartValidatorDebug'])) {
2749 var_dump($e);
2750 }
2751 $this->MAIN->getAdmin()->logErrorToDB($e);
2752 }
2753 }
2754
2755 $this->getCore()->triggerWebhooks(16, $codeObj);
2756 }
2757
2758 public function woocommerce_single_product_summary() {
2759 if ($this->getOptions()->isOptionCheckboxActive('wcTicketDisplayDateOnPrdDetail')) {
2760 global $product;
2761 if (!class_exists("sasoEventtickets_Ticket")){
2762 require_once("sasoEventtickets_Ticket.php");
2763 }
2764
2765 // Retrieve WooCommerce date and time formats
2766 $date_format = get_option('date_format'); // WooCommerce date format
2767 $time_format = get_option('time_format'); // WooCommerce time format
2768
2769 $date_str = $this->MAIN->getTicketHandler()->displayTicketDateAsString($product, $date_format, $time_format);
2770 if (!empty($date_str)) echo "<br>".$date_str;
2771 }
2772 }
2773
2774 function woocommerce_checkout_update_order_meta($order_id, $address_data) {
2775 if ($this->getOptions()->isOptionCheckboxActive('wcRestrictPurchase')) { // not in use anymore. But maybe with old installations
2776 if ($this->containsProductsWithRestrictions()) {
2777 $order = wc_get_order( $order_id );
2778 $items = $order->get_items();
2779 foreach ( $items as $item_id => $item ) {
2780 $code = wc_get_order_item_meta($item_id , $this->meta_key_codelist_restriction_order_item, true);
2781 // speicher orderid und order item id zum code
2782 if (!empty($code)) {
2783 $product_id = $item->get_product_id();
2784 $order_id = $order->get_id();
2785 $list_id = get_post_meta($product_id, $this->meta_key_codelist_restriction, true);
2786 $this->getAdmin()->addRetrictionCodeToOrder($code, $list_id, $order_id, $product_id, $item_id);
2787 }
2788 }
2789 }
2790 }
2791 }
2792
2793 function woocommerce_delete_order_item($item_get_id) {
2794 $code = wc_get_order_item_meta($item_get_id , $this->meta_key_codelist_restriction_order_item, true);
2795 if (!empty($code)) {
2796 $data = ['code'=>$code];
2797 // remove used info
2798 $this->getAdmin()->removeUsedInformationFromCode($data);
2799 $this->getAdmin()->removeWoocommerceOrderInfoFromCode($data);
2800 $this->getAdmin()->removeWoocommerceRstrPurchaseInfoFromCode($data);
2801 // nur zur sicherheit
2802 $this->deleteRestrictionEntryOnOrderItem($item_get_id);
2803 // add note to order
2804 $order_id = wc_get_order_id_by_order_item_id($item_get_id);
2805 $order = wc_get_order( $order_id );
2806 $order->add_order_note( sprintf(/* translators: %s: restriction code number */esc_html__('Order item deleted. Free restriction code: %s for next usage.', 'event-tickets-with-ticket-scanner'), esc_attr($code)) );
2807 }
2808 if ($this->getOptions()->isOptionCheckboxActive('wcRestrictFreeCodeByOrderRefund')) {
2809 $code_value = wc_get_order_item_meta($item_get_id , "_saso_eventtickets_product_code", true);
2810 if (!empty($code_value)) {
2811 $codes = explode(",", $code_value);
2812 foreach($codes as $code) {
2813 $code = trim($code);
2814 if (!empty($code)) {
2815 // nur zur sicherheit
2816 $this->deleteCodesEntryOnOrderItem($item_get_id);
2817 // remove used info - if it is a real ticket number and not the free max usage message
2818 $data = ['code'=>$code];
2819 try {
2820 $this->getAdmin()->removeUsedInformationFromCode($data);
2821 $this->getAdmin()->removeWoocommerceOrderInfoFromCode($data);
2822 $this->getAdmin()->removeWoocommerceRstrPurchaseInfoFromCode($data);
2823 } catch (Exception $e) {
2824 $this->MAIN->getAdmin()->logErrorToDB($e);
2825 }
2826 // add note to order
2827 $order_id = wc_get_order_id_by_order_item_id($item_get_id);
2828 $order = wc_get_order( $order_id );
2829 $order->add_order_note( sprintf(/* translators: %s: ticket number */esc_html__('Order item deleted. Free ticket number: %s for next usage.', 'event-tickets-with-ticket-scanner'), esc_attr($code)) );
2830 }
2831 }
2832 }
2833 }
2834 do_action( $this->MAIN->_do_action_prefix.'woocommerce-hooks_woocommerce_delete_order_item', $item_get_id );
2835 }
2836
2837 private function removeTicketInfosFromOrder( $order_id ) {
2838 $order = wc_get_order( $order_id );
2839 if ($order) {
2840 $items = $order->get_items();
2841 foreach ( $items as $item_id => $item ) {
2842 $this->woocommerce_delete_order_item($item_id);
2843 }
2844 }
2845 }
2846
2847 function woocommerce_delete_order( $id ) {
2848 $this->removeAllTicketsFromOrder(['order_id'=>$id]);
2849 }
2850
2851 function woocommerce_pre_delete_order_refund($ret, $refund, $force_delete) {
2852 if ($refund) {
2853 $this->refund_parent_id = $refund->get_parent_id();
2854 }
2855 return $ret;
2856 }
2857 function woocommerce_delete_order_refund( $id ) {
2858 if ($this->refund_parent_id) {
2859 $this->add_serialcode_to_order($this->refund_parent_id); // add missing ticket numbers
2860 } else {
2861 $this->removeAllTicketsFromOrder(['order_id'=>$id]);
2862 }
2863 }
2864
2865 function deleteCodesEntryOnOrderItem($item_id) {
2866 wc_delete_order_item_meta( $item_id, '_saso_eventtickets_product_code' );
2867 wc_delete_order_item_meta( $item_id, '_saso_eventticket_code_list' );
2868 wc_delete_order_item_meta( $item_id, '_saso_eventtickets_public_ticket_ids' );
2869 wc_delete_order_item_meta( $item_id, '_saso_eventtickets_daychooser' );
2870 }
2871 function deleteRestrictionEntryOnOrderItem($item_id) {
2872 wc_delete_order_item_meta( $item_id, $this->meta_key_codelist_restriction_order_item );
2873 }
2874 function woocommerce_thankyou_($order_id=0) {
2875 $order_id = intval($order_id);
2876 if ( $order_id > 0) {
2877
2878 $order = wc_get_order( $order_id );
2879 if ($order == "") return "";
2880
2881 $isHeaderAdded = false;
2882 $hasTickets = $this->hasTicketsInOrderWithTicketnumber($order);
2883
2884 if ($hasTickets) {
2885 $wcTicketDisplayDownloadAllTicketsPDFButtonOnCheckout = $this->getOptions()->isOptionCheckboxActive('wcTicketDisplayDownloadAllTicketsPDFButtonOnCheckout');
2886 if ($wcTicketDisplayDownloadAllTicketsPDFButtonOnCheckout) {
2887 $url = $this->getCore()->getOrderTicketsURL($order);
2888 $dlnbtnlabel = $this->getOptions()->getOptionValue('wcTicketLabelPDFDownload');
2889 $dlnbtnlabelHeading = $this->getOptions()->getOptionValue('wcTicketLabelPDFDownloadHeading');
2890 echo '<h2>'.esc_html($dlnbtnlabelHeading).'</h2>';
2891 echo '<p><a target="_blank" href="'.esc_url($url).'"><b>'.esc_html($dlnbtnlabel).'</b></a></p>';
2892 $isHeaderAdded = true;
2893 }
2894
2895 $wcTicketDisplayOrderTicketsViewLinkOnCheckout = $this->getOptions()->isOptionCheckboxActive('wcTicketDisplayOrderTicketsViewLinkOnCheckout');
2896 if ($wcTicketDisplayOrderTicketsViewLinkOnCheckout) {
2897 $url = $this->getCore()->getOrderTicketsURL($order, "ordertickets-");
2898 $dlnbtnlabel = $this->getOptions()->getOptionValue('wcTicketLabelOrderDetailView');
2899 if (!$isHeaderAdded) {
2900 $dlnbtnlabelHeading = $this->getOptions()->getOptionValue('wcTicketLabelPDFDownloadHeading');
2901 echo '<h2>'.esc_html($dlnbtnlabelHeading).'</h2>';
2902 }
2903 echo '<p><a target="_blank" href="'.esc_url($url).'"><b>'.esc_html($dlnbtnlabel).'</b></a></p>';
2904 }
2905 }
2906 }
2907 }
2908 }
2909 ?>