Skip to content

Instantly share code, notes, and snippets.

View barryhughes's full-sized avatar
🇨🇦

Barry Hughes barryhughes

🇨🇦
  • Automattic
  • Vancouver Island, Canada
View GitHub Profile
<?php
/**
* Delete attendees if the order they are associated with is changed to a status of "refunded".
*
* Designed to work with Event Tickets Plus 4.7.1. Note that re-stocking of inventory must be
* handled separately/by taking advantage of WooCommerce's own facilities for this.
*/
class Delete_Attendees_Upon_Refund {
static function init() {
add_action( 'woocommerce_order_status_refunded', array( __CLASS__, 'on_refund' ) );
@barryhughes
barryhughes / event-list-remove-events-that-have-already-started.php
Created March 21, 2018 22:33
Remove events (from the upcoming events list) that have already started | TEC 4.6.x
<?php
/**
* "Filter out" events that have already started from list view.
*
* This deviates from the default behaviour which will include events
* that started in the past but are ongoing (have not yet ended).
*/
add_filter( 'posts_where', function( $sql, $query ) {
global $wpdb;
@barryhughes
barryhughes / reorder-photo-view_reverse-by-page.php
Created March 15, 2018 15:23
Reverses the order of posts on each individual photo view page (but does not reverse the sequence as a whole ... for TEC/ECP 4.5/4.6). In other words, this doesn't necessarily mean we'll see the furthest-in-the-future event first, rather it means each page on photo view will contain the same range of events but in the reverse order.
<?php
function photo_view_reorder_posts( $posts ) {
remove_filter( 'the_posts', 'photo_view_reorder_posts' );
return array_reverse( $posts );
}
function photo_view_reorder_listen( $query ) {
if (
'photo' === $query->get( 'eventDisplay' )
|| tribe_is_ajax_view_request( 'photo' )
@barryhughes
barryhughes / cart.php
Created March 13, 2018 08:08
Simplified example of using a redirect to prevent accidental resubmission of form data
<?
// Test early in the request for submitted data
if ( isset( $_POST['some-data'] ) ) {
// Add to cart or do other work with this data
setcookie( 'some-data', $_POST['some-data'] );
// Redirect to prevent resubmissions of the same form
header( 'Location: /cart.php' );
exit();
}
@barryhughes
barryhughes / custom-import-sample.php
Last active February 28, 2018 02:03
Example/starting point for custom import jobs using Eventbrite Tickets 4.4.8
<?php
/**
* Example of searching Eventbrite for events and importing them via
* Eventbrite Tickets.
*
* By design, Eventbrite Tickets 4.4.x allows importing from whichever user
* account it has been linked with as well as individual events belonging to
* other accounts, which can be specified via their ID or URL.
*
* This is an example of searching for and importing a broader swathe of
<?php
/**
* @param string $date (yyyy-mm-dd format)
* @param string $timezone
*
* @return bool|null
*/
function is_dst( $date, $timezone ) {
try {
$datetime = date_create();
@barryhughes
barryhughes / tec-remove-noindex-hints.php
Created February 5, 2018 20:14
Stop The Events Calendar from adding "noindex,follow" tags to event views. Use with caution/read up on soft 404s before using.
<?php
/**
* Plugin name: Remove Events No Index Tag
* Description: Prevents The Events Calendar from telling search engines not to index various views
*/
apply_filters( 'tribe_events_add_no_index_meta', '__return_false' );
<?php
### Example of adding an extra column to the Event Tickets/Event Tickets Plus
### attendee table.
###
### Tested with Event Tickets Plus 4.6.2
# Register our extra column
add_filter( 'tribe_tickets_attendee_table_columns', function( $columns ) {
$columns['extra'] = 'My extra column';
return $columns;
@barryhughes
barryhughes / temp-fix-embedded-month-view-day-links.php
Last active May 2, 2019 16:10
Provides a temp workaround to help ensure the more event/view all X event links within month view are functional
@barryhughes
barryhughes / single-event.php
Created November 29, 2017 22:54
Modified version of the single-event.php template (for TEC 4.6.3 → 4.6.6)
<?php
/**
* Modified single event template.
*
* This deviates from the default template by capturing the previous and next
* event link HTML and re-using it, preventing the same queries from running
* twice unnecessarily.
*
* @version 4.6.3
*/