Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active May 22, 2017 17:18
Show Gist options
  • Save cliffordp/6250485f5fe850e5404059c48de3e3ed to your computer and use it in GitHub Desktop.
Save cliffordp/6250485f5fe850e5404059c48de3e3ed to your computer and use it in GitHub Desktop.
TEC + CE + CE Tickets: If Split Payments is enabled and user does not have their payment email address filled out, show notice at top of Community Events form to alert them to complete their split payments profile before creating an event. * Preview NOT fully hidden: https://cl.ly/0k1z0n300u16 * Preview of fully hidden: https://cl.ly/1h2Q2h1s3F3J
<?php
/**
* TEC + CE + CE Tickets: If Split Payments is enabled and user does not have their payment email address filled out, show notice at top of Community Events form to alert them to complete their split payments profile before creating an event... because they cannot create a ticket for their event until they do so.
*
* Note that this may not be what you want if not all of your event creators create tickets for their events.
*
* Preview without cliff_ce_tix_hide_form_if_no_email(): https://cl.ly/0k1z0n300u16
* Preview WITH cliff_ce_tix_hide_form_if_no_email(): https://cl.ly/1h2Q2h1s3F3J
*
* From https://gist.github.com/cliffordp/6250485f5fe850e5404059c48de3e3ed
*/
add_action( 'tribe_events_community_form_before_template', 'cliff_ce_tix_split_pmts_user_wo_pmt_email' );
function cliff_ce_tix_hide_form_if_no_email() {
echo '<style type="text/css">
body.tribe_community_edit .tribe-community-events div:not(.ce-message-required-before-adding-tickets) {
display: none;
}
</style>';
}
function cliff_ce_tix_split_pmts_user_wo_pmt_email() {
if (
// community tickets enabled
! class_exists( 'Tribe__Events__Community__Tickets__Main' )
|| ! method_exists( Tribe__Events__Community__Tickets__Main::instance(), 'is_enabled' )
|| ! Tribe__Events__Community__Tickets__Main::instance()->is_enabled()
// split payments enabled
|| ! method_exists( Tribe__Events__Community__Tickets__Main::instance(), 'is_split_payments_enabled' )
|| ! Tribe__Events__Community__Tickets__Main::instance()->is_split_payments_enabled()
// user meta
|| ! class_exists( 'Tribe__Events__Community__Tickets__Payment_Options_Form' )
) {
return false;
}
// let's proceed...
$community_tickets = Tribe__Events__Community__Tickets__Main::instance();
$meta = get_user_meta( get_current_user_id(), Tribe__Events__Community__Tickets__Payment_Options_Form::$meta_key, true );
if ( empty( $meta['paypal_account_email'] ) ) {
?>
<div class="ce-message-required-before-adding-tickets" style="padding: 20px; background-color: #ffbedc; margin: 0 auto; text-align: center;">
<?php
printf(
esc_html__(
'Before you can create tickets, please add your PayPal email address on the %1$sPayment options%2$s form.',
'tribe-events-community-tickets'
),
'<a href="' . esc_url( $community_tickets->routes['payment-options']->url() ) . '">',
'</a>'
);
?>
</div>
<?php
add_action( 'wp_head', 'cliff_ce_tix_hide_form_if_no_email' );
} else {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment