Skip to content

Instantly share code, notes, and snippets.

@JudeRosario
Last active August 29, 2015 14:14
Show Gist options
  • Save JudeRosario/b381937e7221d1934c15 to your computer and use it in GitHub Desktop.
Save JudeRosario/b381937e7221d1934c15 to your computer and use it in GitHub Desktop.
Appointments+ Code Snippets
// Global Appointment Object, available when plugin is active
global $appointments;
// Get Appointment by ID
$app = $wpdb->get_row( $wpdb->prepare("SELECT * FROM {$this->app_table} WHERE ID=%d", $app_id) );
// Get ALL Workers
$workers = $appointments->db->get_results("SELECT * FROM " . $appointments->workers_table . " ORDER BY ". esc_sql($order_by) ." " );
// Get Appointments by Status
$results = $wpdb->get_results( "SELECT * FROM " . $appointments->app_table . " WHERE (".$stat.") ORDER BY ".$appointments->sanitize_order_by( $order_by )." " );
// Get Appointments by Transactions
$sql = $this->db->prepare( "SELECT transaction_ID FROM {$appointments->transaction_table} WHERE transaction_app_ID = %d AND transaction_paypal_ID = %s AND transaction_stamp = %d LIMIT 1 ", $app_id, $paypal_ID, $timestamp );
// Append this either as footer script or return this in an AJAX reponse to the front end
<script type="text/javascript">
// Creates an iframe and appends it before the confirmation buttons on the DOM
var iframe = document.createElement('iframe');
$(".appointments-confirmation-buttons").before(iframe);
// Binds each selectable slot to its date and the event is used to generate the Date object
$( "table td.free").bind( "click", function( event ) {
// Convert date to milliseconds
date = new Date(event.target.children[0].value.split(':')[3]*1000);
// Get the date and time as UTC formatted strings
var time = date.getUTCHours()+'.'+(date.getUTCMinutes()/60*100);
var day = (date.getUTCMonth()+1)+'/'+date.getUTCDate()+'/'+date.getUTCFullYear();
// These are split up into smaller strings so that you can manipulate before sending to WTB if required
str1 = '<script src="http://www.worldtimebuddy.com/event_widget.js?h=8&md=';
str2 = '&mt=';
str3 = '&ml=0.50&sts=0&sln=0&wt=ew-lt"><\/script><i><a target="_blank" href="http://www.worldtimebuddy.com/">Time converter</a> at worldtimebuddy.com</i><noscript><a href="http://www.worldtimebuddy.com/">Time converter</a> at worldtimebuddy.com<\/noscript><script>window[wtb_event_widgets.pop()].init()<\/script>';
// Final String to be passed to the API
var string = "";
// Write this as a raw string into the created iframe
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(string.concat(str1,day,str2,time,str3));
iframe.contentWindow.document.close();
});
</script>
@JudeRosario
Copy link
Author

Some snippets that make customizing A+ easy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment