Last active
September 1, 2017 23:14
-
-
Save andrasguseo/6137bcba54151b653c43bb71bd11eb93 to your computer and use it in GitHub Desktop.
Autofill ticket data for WooCommerce Tickets in Event Tickets Plus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Autofill Ticket Data | |
// @namespace test | |
// @description Autofill ticket data for WooCommerce Tickets in Event Tickets Plus | |
// It will add a blue button to the top right of the screen (Add new event / Edit event). | |
// If you click that then ticket data will be automatically filled based on what you have in the script. | |
// | |
// @IMPORTANT: Change the domain name to yours in the below line, otherwise it will not work. | |
// | |
// @include https://yourdomain.com/wp-admin/post-new.php?post_type=tribe_events | |
// @author Andras Guseo | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
// ADDING THE BUTTON TO THE TOP | |
var div = document.createElement('div'); | |
div.setAttribute('class', 'myButtonDiv'); | |
div.setAttribute('style', 'position: fixed; top: 60px; right: 10px; z-index:999999;'); | |
div.innerHTML = '<input type="button" value="Click to fill ticket data" style="background-color: #2ea3f2;color: #fff;font-weight: bold;">'; | |
document.body.insertBefore(div, document.body.firstChild); | |
div.firstChild.addEventListener('click', runMyScript, true); | |
function runMyScript(){ | |
// Shows an alert before running. Delete / comment if not needed. | |
alert('script running'); | |
// Scroll down | |
location.href = "#"; | |
location.href = "#tribetickets"; | |
// Clicks the 'Add new ticket' button | |
document.getElementById('ticket_form_toggle').click(); | |
// Selects the 2nd radio button. If RSVP and WooCommerce tickets are available, then WooCommerce will be selected. | |
var x = document.getElementById('ticket_form_table'); | |
x.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[1].getElementsByTagName('td')[1].getElementsByTagName('input')[1].click(); | |
// Ticket details. Adjust as needed. Delete / comment if not needed. | |
// Note: The hours and minutes will not be visible in the form, | |
// but they are filled out and saved nonetheless. | |
// Ticket Name | |
document.getElementById('ticket_name').value="Single"; | |
// Ticket Description | |
document.getElementById('ticket_description').value="This is a single ticket"; | |
// Start sale | |
document.getElementById('ticket_start_date').value="2017-08-30"; | |
document.getElementById('ticket_start_hour').value="10"; | |
document.getElementById('ticket_start_minute').value="00"; | |
// End sale | |
document.getElementById('ticket_end_date').value="2017-09-10"; | |
document.getElementById('ticket_end_hour').value="10"; | |
document.getElementById('ticket_end_minute').value="00"; | |
// Price | |
document.getElementById('ticket_price').value="10"; | |
// Stock | |
document.getElementById('ticket_woo_stock').value="100"; | |
// SKU | |
document.getElementById('ticket_woo_sku').value="TIX-1"; | |
// Scroll down again | |
location.href = "#"; | |
location.href = "#ticket_form_toggle"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment