Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /********************
- This snippet will enable a sub total in the Single Bookings Booking Form for Events Manager Pro.
- ********************/
- function stonehenge_em_single_booking_subtotal($EM_Ticket) {
- $locale = get_bloginfo('language');
- $ticket_price = $EM_Ticket->get_price(false);
- $currency = get_option('dbem_bookings_currency');
- $taxRate = get_option('dbem_bookings_tax');
- $taxAdd = get_option('dbem_bookings_tax_auto_add');
- $taxName = __('Tax', 'events-manager');
- // Create the Sub Total section on the Booking From.
- ?>
- <style>
- /* Remove this style section if you DO want to show additional tax info, or leave it to hide. */
- #subTax {display:none !important;}
- #extraInfo {display:none !important;}
- </style>
- <?php
- if( get_option('dbem_bookings_tickets_single_form') ) {
- echo '<tr><td><label>' . __('Sub Total', 'events-manager') . '</label></td>';
- echo '<td colspan="2"><strong><span id="subTotal"></span></strong> <small><span id="subTax"></span></small></td></tr>';
- } else {
- echo '<p class="input-user-field em-subtotal"><label>' . __('Sub Total', 'events-manager') . '</label>';
- echo '<strong><span id="subTotal"></span></strong> <small><span id="subTax"></span></small></p>';
- }
- ?>
- <!-- This is where the real magic happens! -->
- <script>
- jQuery.noConflict();
- // Add 0 to Spaces, making required more clear. It will also make the initial Subtotal 0.00.
- jQuery(".em-ticket-select").prepend("<option value='0' selected='selected' disabled='disabled'>---</option>");
- Locale = '<?php echo $locale; ?>';
- TicketPrice = <?php echo $ticket_price; ?>;
- Currency = '<?php echo $currency; ?>';
- TaxRate = <?php echo $taxRate; ?>;
- TaxName = '<?php echo $taxName; ?>';
- addTax = '<?php echo $taxAdd; ?>';
- Spaces = jQuery(".em-ticket-select option:selected").val();
- Price = (Spaces * TicketPrice).toFixed(2);
- // Process Tax added to Ticket Price?
- if( addTax == '1' ) {
- Tax = (Price / (100 + TaxRate) * TaxRate).toFixed(2);
- inclTax = '(incl. ';
- }
- else {
- Tax = (Price / 100 * TaxRate).toFixed(2);
- inclTax = '(excl. ';
- }
- formattedPrice = Number(Price).toLocaleString(Locale, {style: 'currency', currency: Currency });
- formattedTax = Number(Tax).toLocaleString(Locale, {style: 'currency', currency: Currency });
- // Add Tax info to the default ticket price field.
- jQuery(".ticket-price strong").html(Number(TicketPrice).toLocaleString(Locale, {style: 'currency', currency: Currency }));
- jQuery(".ticket-price").append("<span id='extraInfo'> p.p. <small>" + inclTax + TaxRate + "% " + TaxName + ")</small></span>");
- // Display initial sub total amount on page load.
- jQuery("#subTotal").html( formattedPrice );
- jQuery("#subTax").html( inclTax + formattedTax + ' ' + TaxName + ')' );
- // Change the sub total according to the selected spaces.
- jQuery(".em-ticket-select").change(function() {
- var newSpaces = jQuery(".em-ticket-select option:selected").val();
- var newPrice = (newSpaces * TicketPrice ).toFixed(2);
- var newTax = (newPrice / (100 + TaxRate) * TaxRate ).toFixed(2);
- jQuery("#subTotal").html( Number(newPrice).toLocaleString(Locale, { style: 'currency', currency: Currency }) );
- jQuery("#subTax").html(inclTax + Number(newTax).toLocaleString(Locale, { style: 'currency', currency: Currency })+' '+TaxName+')');
- });
- // Optional: Add the required asterisk after the Spaces label. Comment out if needed.
- jQuery("label[for=em_tickets]").append(' <span class="em-form-required">*</span>');
- (jQuery);
- </script>
- <?php
- }
- if( get_option('dbem_bookings_tickets_single_form') ) {
- add_action('em_booking_form_tickets_loop_footer', 'stonehenge_em_single_booking_subtotal');
- } else {
- add_action('em_booking_form_ticket_footer', 'stonehenge_em_single_booking_subtotal');
- }
Advertisement
Add Comment
Please, Sign In to add comment