-
Notifications
You must be signed in to change notification settings - Fork 0
/
event-ticket-plus-shortcode.php
474 lines (348 loc) · 17.4 KB
/
event-ticket-plus-shortcode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<?php
/*
Plugin Name: Event Ticket Plus Shortcode
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: 1.0
Author: bastiW
Author URI: http://URI_Of_The_Plugin_Author
License: GPL2
*/
/*
$post = $_POST;
highlight_string("<?php\n\$pst =\n" . var_export($post, true) . ";\n?>");
*/
function event_tickets_plus_shortcode( $atts ) {
if(is_admin()) {
return;
}
global $woocommerce;
//Default value for clear the woo commerce cart
$emptyCart = true;
$atts = shortcode_atts( array(
'id' => null,
'emptycart' => $emptyCart
), $atts, 'tribe_tickets' );
$tickets = Tribe__Tickets__Tickets::get_all_event_tickets( $atts[id] );
$is_there_any_product = false;
$is_there_any_product_to_sell = false;
//$unavailability_messaging = is_callable( array( $this, 'do_not_show_tickets_unavailable_message' ) );
if ( ! empty( $tickets ) ) {
$tickets = tribe( 'tickets.handler' )->sort_tickets_by_menu_order( $tickets );
}
if($atts['emptycart'] === true || strtolower($atts['emptycart']) === 'true' || $atts['emptycart'] == 1) {
$emptyCart = (bool) true;
} elseif ($atts['emptycart'] === false || strtolower($atts['emptycart']) === 'false' || $atts['emptycart'] == 0 ) {
$emptyCart = (bool) false;
}
if($emptyCart == true) {
$woocommerce->cart->empty_cart();
}
ob_start();
/**
* Filter classes on the Cart Form
*
* @since 4.3.2
*
* @param array $cart_classes
*/
$cart_classes = (array) apply_filters( 'tribe_events_tickets_woo_cart_class', array( 'cart' ) );
?>
<style>
.tribe-ticket-shortcode {
margin: auto;
max-width: 900px;
}
.total-quantity {
background: #f8f8f8;
text-align: center;
border-bottom: 1px solid #dfdfdf;
color: #464646;
font-size: 15px;
padding: 16px 10px;
font-weight: bold;
}
.tribe-events-tickets .tribe-tickets-remaining {
display: none;
}
button.tribe-button {
/* border-color: #E62B1E; */
/* background: #E62B1E; */
color: #fff;
font-family: Poppins, Helvetica, Arial, sans-serif;
display: inline-block;
outline: none;
cursor: pointer;
text-align: center;
text-decoration: none;
padding: .6em 2.5em .6em 2.5em;
color: #fff;
background: #E62B1E;
border: 2px solid #E62B1E;
font-size: 15px;
font-family: 'Poppins', 'Helvetica Neue', Arial,Verdana,sans-serif;
text-shadow: none;
-webkit-appearance: none;
box-shadow: 0 0 0 0;
line-height: 1.5 !important;
border-radius: 5px;
font-style: normal;
font-weight: 500;
-webkit-transition: color .2s linear, background .1s linear, opacity .2s linear;
-moz-transition: color .2s linear, background .1s linear, opacity .2s linear;
-ms-transition: color .2s linear, background .1s linear, opacity .2s linear;
-o-transition: color .2s linear, background .1s linear, opacity .2s linear;
transition: color .2s linear, background .1s linear, opacity .2s linear;
}
.tribe-event-tickets-plus-meta {
display: none;
}
.tribe-events-tickets td.woocommerce, .tribe-events-tickets .quantity, .tribe-events-tickets .tickets_name, .tribe-events-tickets .tickets_price, .tribe-events-tickets .woocommerce {
//border-bottom: none;
}
@media (max-width: 600px) {
button.tribe-button {
width: 100%
}
.tribe-events-tickets, .tribe-events-tickets tbody {
display: table !important;
width: 100%;
}
.tribe-events-style-full .tribe-events-tickets td, .tribe-events-tickets td {
display: table-cell !important;
}
.tribe-events-tickets tr {
display: table-row !important;
}
}
</style>
<div class="tribe-ticket-shortcode">
<div class="tribe-ticket-inner-shortcode">
<form
id="buy-tickets"
action="
<?php
echo esc_url( $woocommerce->cart->get_cart_url() )
?>"
class="<?php echo esc_attr( implode( ' ', $cart_classes ) ); ?>"
method="post"
enctype='multipart/form-data'>
<div class="total-quantity">
<?php
if( $tickets[0]->stock() <= 0 ) {
echo "Ausverkauft! Du kannst dir nach dem Event die Vorträge auf Youtube ansehen. Melde dich zum Newsletter an. Dann geben wir bescheid, wenn die Videos verfügbar sind.";
} elseif ($tickets[0]->stock() <= 20) {
echo "Nur noch " . $tickets[0]->stock() . " Tickets verfügbar";
} else {
echo "Noch " . $tickets[0]->stock() . " Tickets verfügbar";
};
?>
</div>
<table class="tribe-events-tickets">
<?php
/**
* Reorder the tickets per the admin interface order
*
* @since 4.6
*/
foreach ( $tickets as $ticket ) :
/**
* Changing any HTML to the `$ticket` Arguments you will need apply filters
* on the `wootickets_get_ticket` hook.
*/
/**
* @var Tribe__Tickets__Ticket_Object $ticket
* @var WC_Product $product
*/
global $product;
if ( class_exists( 'WC_Product_Simple' ) ) {
$product = new WC_Product_Simple( $ticket->ID );
} else {
$product = new WC_Product( $ticket->ID );
}
$is_there_any_product = true;
$data_product_id = '';
if ( $ticket->date_in_range( current_time( 'timestamp' ) ) ) {
$is_there_any_product = true;
echo sprintf( '<input type="hidden" name="product_id[]" value="%d">', esc_attr( $ticket->ID ) );
/**
* Filter classes on the Price column
*
* @since 4.3.2
*
* @param array $column_classes
* @param int $ticket->ID
*/
$column_classes = (array) apply_filters( 'tribe_events_tickets_woo_quantity_column_class', array( 'woocommerce' ), $ticket->ID );
// Max quantity will be left open if backorders allowed, restricted to 1 if the product is
// constrained to be sold individually or else set to the available stock quantity
$max_quantity = $product->backorders_allowed() ? '' : $product->get_stock_quantity();
$max_quantity = $product->is_sold_individually() ? 1 : $max_quantity;
$available = $ticket->available();
/**
* Filter classes on the row
*
* @since 4.5.5
*
* @param array $row_classes
* @param int $ticket->ID
*/
$row_classes = (array) apply_filters( 'tribe_events_tickets_row_class', array( 'woocommerce', 'tribe-tickets-form-row' ), $ticket->ID );
echo '<tr class="' . esc_attr( implode( ' ', $row_classes ) ) . '" data-product-id="' . esc_attr( $ticket->ID ) . '">';
/**
* Filter classes on the Price column
*
* @since 4.3.2
*
* @param array $column_classes
*/
$column_classes = (array) apply_filters( 'tribe_events_tickets_woo_quantity_column_class', array( 'woocommerce' ) );
echo '<td class="' . esc_attr( implode( ' ', $column_classes ) ) . '" data-product-id="' . esc_attr( $ticket->ID ) . '">';
if ( 0 !== $available ) {
// Max quantity will be left open if backorders allowed, restricted to 1 if the product is
// constrained to be sold individually or else set to the available stock quantity
$stock = $ticket->stock();
$max_quantity = $product->backorders_allowed() ? '' : $stock;
$max_quantity = $product->is_sold_individually() ? 1 : $max_quantity;
$available = $ticket->available();
woocommerce_quantity_input( array(
'input_name' => 'quantity_' . $ticket->ID,
'input_value' => 0,
'min_value' => 0,
'max_value' => $must_login ? 0 : $max_quantity, // Currently WC does not support a 'disable' attribute
) );
$is_there_any_product_to_sell = true;
if ( $available ) {
?>
<span class="tribe-tickets-remaining">
<?php
$readable_amount = tribe_tickets_get_readable_amount( $available, null, false );
echo sprintf( esc_html__( '%1$s available', 'event-tickets-plus' ),
'<span class="available-stock" data-product-id="' . esc_attr( $ticket->ID ) . '">' . esc_html( $readable_amount ) . '</span>'
);
?>
</span>
<?php
}
do_action( 'wootickets_tickets_after_quantity_input', $ticket, $product );
} else {
echo '<span class="tickets_nostock">' . esc_html__( 'Out of stock!', 'event-tickets-plus' ) . '</span>';
}
echo '</td>';
echo '<td class="tickets_name">' . $ticket->name . '</td>';
echo '<td class="tickets_price">';
if ( method_exists( $product, 'get_price' ) && $product->get_price() ) {
echo $product->get_price_html( $product );
} else {
esc_html_e( 'Free', 'event-tickets-plus' );
}
echo '</td>';
//echo '<td class="tickets_description">' . ( $ticket->show_description() ? $ticket->description : '' ) . '</td>';
echo '</tr>';
if ( $product->is_in_stock() ) {
/**
* Use this filter to hide the Attendees List Optout
*
* @since 4.5.2
*
* @param bool
*/
$hide_attendee_list_optout = apply_filters( 'tribe_tickets_plus_hide_attendees_list_optout', false );
if ( ! $hide_attendee_list_optout
&& class_exists( 'Tribe__Tickets_Plus__Attendees_List' )
&& ! Tribe__Tickets_Plus__Attendees_List::is_hidden_on( get_the_ID() )
) { ?>
<tr class="tribe-tickets-attendees-list-optout">
<td colspan="4">
<input
type="checkbox"
name="optout_<?php echo esc_attr( $ticket->ID ); ?>"
id="tribe-tickets-attendees-list-optout-edd"
>
<label for="tribe-tickets-attendees-list-optout-edd"><?php esc_html_e( "Don't list me on the public attendee list", 'event-tickets-plus' ); ?></label>
</td>
</tr>
<?php
}
include Tribe__Tickets_Plus__Main::instance()->get_template_hierarchy( 'meta.php' );
}
}
endforeach; ?>
<?php if ( $is_there_any_product_to_sell ) : ?>
<tr>
<td colspan="4" class="woocommerce add-to-cart">
<?php if ( $must_login ) : ?>
<?php include Tribe__Tickets_Plus__Main::instance()->get_template_hierarchy( 'login-to-purchase' ); ?>
<?php else: ?>
<button
type="submit"
name="wootickets_process"
value="1"
class="tribe-button"
>
<?php esc_html_e( 'Add to cart', 'event-tickets-plus' );?>
</button>
<?php endif; ?>
</td>
</tr>
<?php endif; ?>
<noscript>
<tr>
<td class="tribe-link-tickets-message">
<div class="no-javascript-msg"><?php esc_html_e( 'You must have JavaScript activated to purchase tickets. Please enable JavaScript in your browser.', 'event-tickets-plus' ); ?></div>
</td>
</tr>
</noscript>
</table>
</form>
</div>
</div>
<script>
document.getElementsByClassName("cw_qty")[0].value = 1
</script>
<?php
$output = ob_get_contents();
ob_end_clean();
return $output;
//return var_dump($tickets);
//return var_dump(tribe_events_has_soldout($atts['id']));
//tribe_tickets_parent_post($atts['id']);
}
add_shortcode( 'evtp-tickets', 'event_tickets_plus_shortcode' );
function woocommerce_quantity_input($data = null) {
global $product;
if (!$data) {
$defaults = array(
'input_name' => 'quantity',
'input_value' => '1',
'max_value' => apply_filters( 'woocommerce_quantity_input_max', '', $product ),
'min_value' => apply_filters( 'woocommerce_quantity_input_min', '', $product ),
'step' => apply_filters( 'woocommerce_quantity_input_step', '1', $product ),
'style' => apply_filters( 'woocommerce_quantity_style', 'float:left;', $product )
);
} else {
$defaults = array(
'input_name' => $data['input_name'],
'input_value' => $data['input_value'],
'step' => apply_filters( 'cw_woocommerce_quantity_input_step', '1', $product ),
'max_value' => apply_filters( 'cw_woocommerce_quantity_input_max', '', $product ),
'min_value' => apply_filters( 'cw_woocommerce_quantity_input_min', '', $product ),
'style' => apply_filters( 'cw_woocommerce_quantity_style', 'float:left;', $product )
);
}
if ( ! empty( $defaults['min_value'] ) )
$min = $defaults['min_value'];
else $min = 0;
if ( ! empty( $defaults['max_value'] ) )
$max = $defaults['max_value'];
else $max = 4;
if ( ! empty( $defaults['step'] ) )
$step = $defaults['step'];
else $step = 1;
$options = '';
for ( $count = $min; $count <= $max; $count = $count+$step ) {
$selected = $count === $defaults['input_value'] ? ' selected' : '';
$options .= '<option value="' . $count . '"'.$selected.'>' . $count . '</option>';
}
echo '<div class="cw_quantity_select" style="' . $defaults['style'] . '"><select name="' . esc_attr( $defaults['input_name'] ) . '" title="' . _x( 'Qty', 'Product Description', 'woocommerce' ) . '" class="cw_qty">' . $options . '</select></div>';
}