-
-
Save cliffordp/9edebb79954507935ddb8a9b323ae1b5 to your computer and use it in GitHub Desktop.
Hide ET/ET+ forms on single event pages if JavaScript is disabled. Useful when Attendee Meta fields are used. WITH THIS SNIPPET, when JavaScript is disabled: https://cl.ly/1N452v3T3O17
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
<?php | |
/* | |
* from https://gist.github.com/cliffordp/9edebb79954507935ddb8a9b323ae1b5 | |
* | |
* The Events Calendar and Event Tickets / Event Tickets Plus | |
* Hide ET/ET+ forms on single event pages if JavaScript is disabled | |
* And display text informing the user in a <noscript> tag | |
* Useful when Attendee Meta fields are used -- currently do not get displayed (even Required fields) unless browser has JavaScript enabled (ref: https://central.tri.be/issues/63912) | |
* | |
* Without this snippet: | |
* With JavaScript enabled: https://cl.ly/0H2M3H3g0S1f | |
* With JavaScript disabled: https://cl.ly/2G3c3Y2A2p2S | |
* | |
* WITH THIS SNIPPET, when JavaScript is disabled: https://cl.ly/1N452v3T3O17 | |
* | |
* @link https://www.w3.org/TR/html401/interact/scripts.html#edef-NOSCRIPT | |
* | |
*/ | |
add_action( 'wp_head', 'cliff_et_if_js_disabled_hide_tickets' ); | |
function cliff_et_if_js_disabled_hide_tickets() { | |
// cannot do | |
// remove_action( 'tribe_events_single_event_after_the_meta', array( 'Tribe__Tickets__Tickets', 'front_end_tickets_form' ), 5 ); | |
// because we do not know if JavaScript is enabled at the point that would run... so we have to hide via CSS, at least for this hack | |
$id = get_the_ID(); | |
if ( ! function_exists( 'tribe_is_event' ) || ! tribe_is_event( $id ) ) { | |
return false; | |
} | |
// tribe_events_has_soldout() also TRUE if event has no tickets whatsoever | |
if ( ! function_exists( 'tribe_events_has_soldout' ) || tribe_events_has_soldout( $id ) ) { | |
return false; | |
} | |
echo '<style type="text/css"> | |
body.tribe-no-js #buy-tickets ~ form { | |
display: none !important; | |
} | |
body.tribe-no-js #event-tickets-noscript { | |
margin: 20px auto; | |
border: 4px solid red; | |
padding: 20px; | |
} | |
body.tribe-no-js #event-tickets-noscript p:last-child { | |
margin-bottom: 0; | |
} | |
</style>'; | |
add_action( 'tribe_events_single_event_after_the_meta', 'cliff_et_if_js_disabled_add_noscript_text' ); | |
} | |
// @link https://developer.wordpress.org/reference/functions/esc_html/ | |
function cliff_et_if_js_disabled_add_noscript_text() { | |
printf( '<div id="event-tickets-noscript"><noscript>%1$s | |
<p>%2$s</p> | |
<p>%3$s <a href="http://enable-javascript.com/" target="_blank"><strong>enabling JavaScript</strong></a> (link opens in a new window)</p> | |
<p>%4$s</p> | |
</noscript></div>%1$s', | |
PHP_EOL, // 1 | |
esc_html( 'Tickets are available for this event, but you must enable JavaScript in order to order them! :(' ), // 2 | |
esc_html( 'Please come back to this page after'), // 3 | |
esc_html( 'Thank you.' ) // 4 | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment