Skip to content

Instantly share code, notes, and snippets.

@xrazis
Created June 17, 2021 20:21
Show Gist options
  • Save xrazis/ba31f63b324a1f8da645cce79a8760a2 to your computer and use it in GitHub Desktop.
Save xrazis/ba31f63b324a1f8da645cce79a8760a2 to your computer and use it in GitHub Desktop.
The events calendar + events ticket WP add on does not (yet) support recurring tickets. Quick fix, edit to your need.
// In order for this to work the 'post' param must be incrimental (series event).
const ticketTime = 2;
let postCount;
// Get `post` from URLsearchParams
getPostCount = () => {
params = (new URL(document.location)).searchParams;
postCount = params.get('post');
postCount++
}
createTickets = () => {
// Adult ticket
document.getElementById("ticket_form_toggle").click();
document.getElementById("ticket_name").value="Adult";
document.getElementById("ticket_price").value="20";
document.getElementById("Tribe__Tickets__Commerce__PayPal__Main_capacity").value="20";
document.getElementById("ticket_form_save").click();
// Child ticket
document.getElementById("ticket_form_toggle").click();
document.getElementById("ticket_name").value="Child";
document.getElementById("ticket_price").value="10";
document.getElementById("Tribe__Tickets__Commerce__PayPal__Main_capacity").value="20";
document.getElementById("ticket_form_save").click();
// Update the event
window.setTimeout(() => {
document.getElementById("publish").click();
}, (ticketTime * 1000) / 2);
}
// Navigate to the next event
changePage = () => {
window.setTimeout(() => {
const newURL = `${window.location.protocol}//${window.location.host}${window.location.pathname}?post=${postCount}&action=edit`;
window.history.pushState({path: newURL}, '', newURL);
window.history.go();
}, ticketTime * 1000);
}
(exec = () => {
getPostCount();
createTickets();
changePage();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment