Skip to content

Instantly share code, notes, and snippets.

@sc0ttkclark
Created December 11, 2020 14:56
Show Gist options
  • Save sc0ttkclark/28064e516f8702ba1a60d8049e2a74d7 to your computer and use it in GitHub Desktop.
Save sc0ttkclark/28064e516f8702ba1a60d8049e2a74d7 to your computer and use it in GitHub Desktop.
To fix Avada double attendee issues -- replace the file in event-tickets/src/resources/js/tickets-registration-page.min.js with the following file contents
void 0===window.tribe&&(window.tribe={}),void 0===window.tribe.tickets&&(window.tribe.tickets={}),window.tribe.tickets.registration={},function(t,e){e.document=t(document),e.hasChanges={},e.selector={footerQuantity:".tribe-tickets__footer__quantity__number",footerAmount:".tribe-tickets__footer__total .tribe-amount",checkout:".tribe-tickets__registration__checkout",checkoutButton:".tribe-tickets__item__registration__submit",container:".tribe-tickets__registration",eventContainer:".tribe-tickets__registration__event",field:{text:".tribe-tickets__item__attendee__field__text",checkbox:".tribe-tickets__item__attendee__field__checkbox",select:".tribe-tickets__item__attendee__field__select",radio:".tribe-tickets__item__attendee__field__radio"},fields:".tribe-tickets__item__attendee__fields",fieldsError:".tribe-tickets__item__attendee__fields__error",fieldsErrorAjax:".tribe-tickets__item__attendee__fields__error--ajax",fieldsErrorRequired:".tribe-tickets__item__attendee__fields__error--required",fieldsSuccess:".tribe-tickets__item__attendee__fields__success",form:"#tribe-tickets__registration__form",item:".tribe-tickets__item",itemPrice:".tribe-amount",itemQuantity:".tribe-ticket-quantity",loader:".tribe-common-c-loader",metaField:".ticket-meta",metaItem:".tribe-ticket",metaForm:".tribe-tickets__registration__content",miniCart:"#tribe-tickets__mini-cart",status:".tribe-tickets__registration__status",toggler:".tribe-tickets__registration__toggle__handler",horizontal_datepicker:{container:".tribe_horizontal_datepicker__container",select:".tribe_horizontal_datepicker__container select",day:".tribe_horizontal_datepicker__day",month:".tribe_horizontal_datepicker__month",year:".tribe_horizontal_datepicker__year",value:".tribe_horizontal_datepicker__value"}};const i=t(e.selector.container);t(e.selector.eventContainer).length&&(e.commerceSelector={edd:"Tribe__Tickets_Plus__Commerce__EDD__Main",rsvp:"Tribe__Tickets__RSVP",tpp:"Tribe__Tickets__Commerce__PayPal__Main",Tribe__Tickets__Commerce__PayPal__Main:"tribe-commerce",Tribe__Tickets__RSVP:"rsvp",Tribe__Tickets_Plus__Commerce__EDD__Main:"edd",Tribe__Tickets_Plus__Commerce__WooCommerce__Main:"woo",tribe_eddticket:"edd",tribe_tpp_attendees:"tpp",tribe_wooticket:"woo",woo:"Tribe__Tickets_Plus__Commerce__WooCommerce__Main"},e.provider=i.data("provider"),e.providerId=e.commerceSelector[e.provider],e.getMetaForSave=function(){const i=t(e.selector.metaForm).find(e.selector.metaItem),o=[],r=[];return i.each(function(){const i={},o=t(this),n=o.data("ticketId"),c=o.find(e.selector.metaField);c.length&&(r[n]||(r[n]={},r[n].ticket_Id=n,r[n].items=[]),c.each(function(){const e=t(this);let o=e.val();const r=e.is(":radio");let n=e.attr("name");if(n=(n=n.split("[")).pop().replace("]",""),(r||e.is(":checkbox"))&&!e.prop("checked")){if(r&&""!==i[n])return;o=""}i[n]=o}),r[n].items.push(i))}),Object.keys(r).forEach(function(t){const e={ticket_id:t,items:r[t].items};o.push(e)}),o},e.getTicketsForSave=function(){const i=[];let o=t(e.selector.miniCart);return o.length||(o=t(e.selector.container)),o.find(e.selector.item).each(function(){const o=t(this),r=o.data("ticketId"),n=o.find(e.selector.itemQuantity).text(),c={};c.ticket_id=r,c.quantity=n,i.push(c)}),i},e.initFormPrefills=function(){t.ajax({type:"GET",data:{provider:e.providerId,post_id:e.postId},dataType:"json",url:e.getRestEndpoint(),success:function(i){i.tickets&&e.prefillCartForm(t(e.selector.miniCart),i.tickets),i.meta&&(e.appendARFields(i),e.prefillMetaForm(i),window.dispatchEvent(new Event("tribe_et_after_form_prefills")))},complete:function(){e.loaderHide()}})},e.appendARFields=function(o){const r=o.tickets;let n=0,c=0;t.each(r,function(t,e){const o=window.wp.template("tribe-registration--"+e.ticket_id),r=i.find('.tribe-tickets__item__attendee__fields__container[data-ticket-id="'+e.ticket_id+'"]');r.length?c+=e.quantity:n+=e.quantity,r.addClass("tribe-tickets--has-tickets");for(let t=1;t<=e.quantity;++t){const e={attendee_id:t};try{r.append(o(e))}catch(t){}}}),e.maybeShowNonMetaNotice(n,c)},e.maybeShowNonMetaNotice=function(e,i){const o=t(".tribe-tickets__notice--non-ar");0<e&&0<i?(t("#tribe-tickets__non-ar-count").text(e),o.removeClass("tribe-common-a11y-hidden")):o.addClass("tribe-common-a11y-hidden")},e.prefillMetaForm=function(e,o){let r=o;if(void 0===e||0>=e.length)return;void 0===r&&(r=0);const n=i.find(".tribe-tickets__item__attendee__fields__container");let c=e.meta;0<r&&(c=c.splice(0,r-1)),t.each(c,function(e,i){const o=n.filter('[data-ticket-id="'+i.ticket_id+'"]');if(!o.length)return;let r=0;t.each(i.items,function(e,i){if("object"!=typeof i)return;const n=o.find(".tribe-ticket");t.each(i,function(e,i){const o=n.eq(r).find('[name*="'+e+'"]');o.is(":radio")||o.is(":checkbox")?o.each(function(){const e=t(this);i===e.val()&&e.prop("checked",!0)}):o.val(i)}),r++})})},e.updateFooter=function(){e.updateFooterCount(),e.updateFooterAmount()},e.updateFooterCount=function(){const i=t(e.selector.miniCart),o=i.find(e.selector.footerQuantity);let r=0;i.find(e.selector.itemQuantity).each(function(){let e=parseInt(t(this).text(),10);e=isNaN(e)?0:e,r+=e}),0>r||o.text(r)},e.updateFooterAmount=function(){const i=t(e.selector.miniCart),o=i.find(e.selector.footerAmount);let r=0;i.find(e.selector.itemQuantity).each(function(){const i=t(this),o=i.closest(e.selector.item).find(e.selector.itemPrice).first(0);let n=parseInt(i.text(),10);n=isNaN(n)?0:n;const c=e.cleanNumber(o.text())*n;r+=c}),0>r||o.text(e.numberFormat(r))},e.prefillCartForm=function(i,o){t.each(o,function(t,o){const r=i.find('[data-ticket-id="'+o.ticket_id+'"]');if(r){const t=r.find(".tribe-tickets__sale_price .tribe-amount").text();r.find(".tribe-ticket-quantity").html(o.quantity);let i=o.quantity*e.cleanNumber(t);i=e.numberFormat(i),r.find(".tribe-tickets__item__total .tribe-amount").html(i)}}),e.updateFooter()},e.validateForm=function(i){const o=i.find(e.selector.metaItem);let r=!0,n=0;return o.each(function(){const i=t(this);e.validateBlock(i)||(n++,r=!1)}),[r,n]},e.validateBlock=function(i){const o=i.find(e.selector.metaField);let r=!0;return o.each(function(){const i=t(this);e.validateField(i[0])||(r=!1)}),r?i.removeClass("tribe-ticket-item__has-error"):i.addClass("tribe-ticket-item__has-error"),r},e.validateCheckboxRadioGroup=function(i){const o=i.find(e.selector.metaField);let r=!1,n=!0;return o.each(function(){const e=t(this);e.is(":checked")&&(r=!0),e.prop("required")||(n=!1)}),!n||r},e.validateField=function(i){const o=t(i);let r=i.checkValidity();if(!r)if(o.is(":checkbox")||o.is(":radio")){const t=o.closest(".tribe-common-form-control-checkbox-radio-group");t.length&&(r=e.validateCheckboxRadioGroup(t))}else r=!1;if(o.hasClass(e.selector.horizontal_datepicker.value.replace(/^\./,""))){const t=o.closest(e.selector.horizontal_datepicker.container);[t.find(e.selector.horizontal_datepicker.day),t.find(e.selector.horizontal_datepicker.month),t.find(e.selector.horizontal_datepicker.year)].forEach(function(t){isNaN(parseInt(t.val()))||parseInt(t.val())<=0?(t.addClass("ticket-meta__has-error"),r=!1):t.removeClass("ticket-meta__has-error")})}return r?o.removeClass("ticket-meta__has-error"):o.addClass("ticket-meta__has-error"),r},e.focusTicketBlock=function(i){t(i).closest(e.selector.metaItem).addClass("tribe-ticket-item__has-focus")},e.unfocusTicketBlock=function(i){t(i).closest(e.selector.metaItem).removeClass("tribe-ticket-item__has-focus")},e.loaderShow=function(){t(e.selector.loader).removeClass("tribe-common-a11y-hidden")},e.loaderHide=function(){t(e.selector.loader).addClass("tribe-common-a11y-hidden")},e.getRestEndpoint=function(){return TribeCartEndpoint.url},e.getCurrencyFormatting=function(){return JSON.parse(TribeCurrency.formatting)[e.commerceSelector[e.providerId]]},e.cleanNumber=function(t){let i=t;const o=e.getCurrencyFormatting();if(o.thousands_sep===o.decimal_point){const t=i.length-(o.number_of_decimals+1);i=(i=(i=i.substr(0,t)+"_"+i.substr(t+1)).split(o.thousands_sep).join("")).split("_").join(".")}else i=(i=i.split(o.thousands_sep).join("")).split(o.decimal_point).join(".");return i},e.numberFormat=function(t){const i=e.getCurrencyFormatting();if(!i)return!1;const o=i.number_of_decimals,r=i.decimal_point,n=i.thousands_sep,c=isFinite(+t)?+t:0,a=isFinite(+o)?Math.abs(o):0,s=void 0===n?",":n,_=void 0===r?".":r,d=(a?function(t,e){const i=Math.pow(10,e);return Math.round(t*i)/i}(c,a):Math.round(c)).toString().split(_);return d[0].length>3&&(d[0]=d[0].replace(/\B(?=(?:\d{3} )+(?!\d))/g,s)),(d[1]||"").length<a&&(d[1]=d[1]||"",d[1]+=new Array(a-d[1].length+1).join("0")),d.join(_)},e.document.on("focus",".tribe-ticket .ticket-meta",function(t){const i=t.target;e.focusTicketBlock(i)}),e.document.on("blur",".tribe-ticket .ticket-meta",function(t){const i=t.target;e.unfocusTicketBlock(i)}),e.document.on("click",e.selector.checkoutButton,function(i){i.preventDefault();const o=t(e.selector.metaForm),r=t(".tribe-tickets__notice--error"),n=e.validateForm(o);if(!n[0])return t([document.documentElement,document.body]).animate({scrollTop:t(".tribe-tickets__registration").offset().top},"slow"),t(".tribe-tickets__notice--error__count").text(n[1]),r.show(),!1;r.hide(),e.loaderShow();const c={tribe_tickets_provider:e.commerceSelector[e.tribe_ticket_provider],tribe_tickets_tickets:e.getTicketsForSave(),tribe_tickets_meta:e.getMetaForSave(),tribe_tickets_post_id:e.postId};t("#tribe_tickets_ar_data").val(JSON.stringify(c)),t(e.selector.form).submit()}),e.init=function(){e.loaderShow(),e.initFormPrefills()},e.document.ready(function(){e.init()}))}(jQuery,window.tribe.tickets.registration);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment