Skip to content

Instantly share code, notes, and snippets.

@altuno
Created March 19, 2020 10:03
Show Gist options
  • Save altuno/4f655acdd62bee9871332d6a39495739 to your computer and use it in GitHub Desktop.
Save altuno/4f655acdd62bee9871332d6a39495739 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Site plugin for genevaphotoclub.com
Description: Site specific code for genevaphotoclub.com
*/
/* Begin Adding Functions Below This Line; Do not include an opening PHP tag as this sample code already includes one! */
add_action( 'init', function() {
remove_all_filters( 'rest_url' );
} );
//* Gravity forms hide labels option enable
add_filter( 'gform_enable_field_label_visibility_settings', '__return_true' );
//* WooCommerce remove related products
remove_action( 'woocommerce_after_single_product_summary', array( $avada_woocommerce, 'output_related_products' ), 15 );
remove_action( 'woocommerce_after_single_product_summary', array( $avada_woocommerce, 'upsell_display' ), 10 );
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
/**
* @snippet Remove Additional Information Tab @ WooCommerce Single Product Page
* @how-to Watch tutorial @ https://businessbloomer.com/?p=19055
* @sourcecode https://businessbloomer.com/?p=317
* @author Rodolfo Melogli
* @testedwith WooCommerce 3.3.4
*/
add_filter( 'woocommerce_product_tabs', 'bbloomer_remove_product_tabs', 98 );
function bbloomer_remove_product_tabs( $tabs ) {
unset( $tabs['additional_information'] );
return $tabs;
}
/**
* ------------------------------------------------------------------------
//* ULTIMATE MEMBERS MODIFICATIONS:
* ------------------------------------------------------------------------
*/
/**
* Returns a user meta value
* Usage [um_user user_id="" meta_key="" ] // leave user_id empty if you want to retrive the current user's meta value.
* meta_key is the field name that you've set in the UM form builder
* you can simple use [um_user meta_key="first_name"] to get the first name or [um_user meta_key="last_name"] to get the last name.
* You can modify the return meta_value with filter hook 'um_user_shortcode_filter__{$meta_key}'
*/
add_shortcode('um_user',function($atts){
if(is_user_logged_in()){
$user_id = get_current_user_id();
if(!is_array($atts) || empty($atts)){
return '';
}else{
extract($atts);
return get_user_meta($user_id,$meta_key,true);
}
}
});
/**
* ------------------------------------------------------------------------
//* EVENT ESPRESSO MODIFICATIONS:
* ------------------------------------------------------------------------
*/
// Select Switzerland by default in the address field
add_action(
'wp_enqueue_scripts',
'my_change_default_ee_country_option',
20
);
function my_change_default_ee_country_option(){
$custom_js = 'jQuery(document).ready(function($){';
$custom_js .= '$(".ee-reg-qstn-country").val("CH");';
$custom_js .= '});';
wp_add_inline_script('ee_form_section_validation', $custom_js);
}
//* Disable email match forced login - EE4 WP User Integration
add_filter( 'EED_WP_Users_SPCO__verify_user_access__perform_email_user_match_check', 'ee_wp_users_remove_email_user_match_check_logged_out' );
function ee_wp_users_remove_email_user_match_check_logged_out() {
if ( ! is_user_logged_in() ) {
return false;
} else {
return true;
}
}
//This function removes tickets with no capabilties set on the ticket, WITHOUT first checking for an event meta value.
//It also displays the standard messages EE would normally show if the logged in user is a subscriber.
//This is a bit of a hack as you should pass role names to current_user_can() but for the time being it will work.
function tw_ee_hide_no_cap_tickets_from_logged_in_users( $return_value, $ticket, $max, $min, $required_ticket_sold_out, $ticket_price, $ticket_bundle, $ticket_status, $status_class) {
$cap_required = $ticket->get_extra_meta( 'ee_ticket_cap_required', true );
if( empty( $cap_required ) && ( is_user_logged_in() && ! current_user_can( 'manage_options') ) ) {
if( ! current_user_can( 'um-member' ) ){
return $return_value;
} else {
return '';
}
}
return $return_value;
}
add_filter( 'FHEE__ticket_selector_chart_template__do_ticket_inside_row', 'tw_ee_hide_no_cap_tickets_from_logged_in_users', 20, 9);
//------------------------------------------------------------------------
//* Add a label for the promotion code field
add_filter( 'FHEE__EED_Promotions___add_promotions_form_inputs__ee_promotion_code_input__html_label_text', 'ee_registration_checkout_promotions_heading' );
function ee_registration_checkout_promotions_heading() {
return 'Avez-vous un code de promo? · Got a promo code?';
}
//------------------------------------------------------------------------
// Add total tax amount column to the EE4 Registrations csv download
add_filter(
'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
'espresso_add_total_taxes_column',
10,
2
);
function espresso_add_total_taxes_column( $reg_csv_array, $reg_row ) {
$registration = EEM_Registration::instance()->get_one_by_ID( $reg_row['Registration.REG_ID'] );
if( $registration instanceof EE_Registration && $registration->is_primary_registrant() ) {
$sub_line_items = EEM_Line_Item::instance()->get_all(
array(
array(
'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
'LIN_type' => EEM_Line_Item::type_tax_sub_total
)
)
);
$sub_line_item_details = array();
foreach( $sub_line_items as $sub_line_item ) {
$sub_line_item_details[] = $sub_line_item->get_pretty( 'LIN_total', 'localized_float' );
}
$reg_csv_array[ __( 'Total Taxes', 'event_espresso' ) ] = implode('+', $sub_line_item_details );
}
return $reg_csv_array;
}
// Add event categories to EE4 csv download
function ee_tw_event_categories_to_csv( $reg_csv_array, $reg_row ) {
$EVT_ID = $reg_row[ 'Event_CPT.ID'];
$terms = array();
$event_categories = get_the_terms( $EVT_ID, 'espresso_event_categories' );
if ( $event_categories ) {
foreach( $event_categories as $term ) {
$terms[] = $term->name;
}
$terms = implode( ', ', $terms);
}
$reg_csv_array['Event Categories'] = !empty($terms) ? $terms : null;
return $reg_csv_array;
}
add_filter( 'FHEE__EE_Export__report_registrations__reg_csv_array', 'ee_tw_event_categories_to_csv', 10, 2 );
//* Add instructor name to EE4 CSV Download
add_filter( 'FHEE__EE_Export__report_registrations__reg_csv_array', 'espresso_add_author_to_report', 10, 2);
function espresso_add_author_to_report( $reg_csv_array, $reg_row ) {
$event_id = $reg_row['Registration.EVT_ID'];
$event = EEM_Event::instance()->get_one_by_ID( $event_id );
if ( $event instanceof EE_Event ) {
$post_author = get_post_field( 'post_author', $event_id );
$author_info = get_userdata( $post_author );
$reg_csv_array['Author'] = $author_info->last_name . ", " . $author_info->first_name;
}
return $reg_csv_array;
}
//* Add language tags to the CSV Download
add_filter( 'FHEE__EE_Export__report_registrations__reg_csv_array', 'espresso_add_tag_to_report', 10, 2);
function espresso_add_tag_to_report( $reg_csv_array, $reg_row ) {
$event_id = $reg_row['Registration.EVT_ID'];
$event = EEM_Event::instance()->get_one_by_ID( $event_id );
if ( $event instanceof EE_Event ) {
$posttags = get_the_tags( $event_id );
if ($posttags) {
foreach($posttags as $tag) {
$reg_csv_array['Tag'] = $tag->name;
}
}
}
return $reg_csv_array;
}
//* Add Venue to CSV Download
add_filter( 'FHEE__EE_Export__report_registrations__reg_csv_array', 'espresso_add_venue_to_report', 10, 2);
function espresso_add_venue_to_report( $reg_csv_array, $reg_row ) {
$event_id = $reg_row['Registration.EVT_ID'];
$event = EEM_Event::instance()->get_one_by_ID( $event_id );
if ( $event instanceof EE_Event ) {
$venue = $event->get_first_related( 'Venue' );
if ( $venue instanceof EE_Venue ) {
$venue_name = !empty( $venue ) ? $venue->name() : '';
$reg_csv_array['Venue'] = $venue_name;
}
}
return $reg_csv_array;
}
//-----------------------------------------------------------------------
// Register Now button text
function ee_register_now_button() {
return 'Register · S\'inscrire';
}
add_filter ('FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', 'ee_register_now_button');
// Finalize Registration button text
function ee_modify_button_text( $submit_button_text, EE_Checkout $checkout ) {
if ( ! $checkout instanceof EE_Checkout || ! $checkout->current_step instanceof EE_SPCO_Reg_Step || ! $checkout->next_step instanceof EE_SPCO_Reg_Step ) {
return $submit_button_text;
}
if ( $checkout->next_step->slug() == 'finalize_registration' ) {
$submit_button_text = 'Finalize registration · Finaliser l\'inscription';
}
return $submit_button_text;
}
add_filter( 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_modify_button_text', 10, 2);
// promotion button text
function ee_modify_promotions_button_text() {
return 'Utiliser · Apply';
}
add_filter( 'FHEE__EED_Promotions___add_promotions_form_inputs__ee_promotion_code_submit__default', 'ee_modify_promotions_button_text' );
// Proceed to Payment Options text
function ee_proceed_to_button( $submit_button_text, EE_Checkout $checkout ) {
if ( ! $checkout instanceof EE_Checkout || ! $checkout->current_step instanceof EE_SPCO_Reg_Step || ! $checkout->next_step instanceof EE_SPCO_Reg_Step ) {
return $submit_button_text;
}
if ( $checkout->next_step->slug() == 'payment_options' ) {
$submit_button_text = 'Proceed to Payment · Procéder au Paiement';
}
return $submit_button_text;
}
add_filter ( 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_proceed_to_button', 10, 2 );
// general text strings
function ee_general_filter_gettext( $translated, $original, $domain ) {
// This is an array of original strings
// and what they should be replaced with
$strings = array(
'Event Phone:' => 'For questions · Numero d\'appel:',
'Important information regarding your payment' => '',
'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.' => '',
'Details' => '',
'Please Select Your Method of Payment' => 'Sélectionnez votre mode de paiement · Please select Your Method of Payment',
'Registrations:' => 'Nombre d\'inscriptions · Number of registrations',
'Name and Description' => '',
'Price' => 'Price · Prix',
'Qty' => 'Qty · Qté',
'Total' => 'Total',
'Line Item' => '',
'Address' => 'Address · Adresse',
'City' => 'City · Ville',
'Country' => 'Country · Pays',
'Zip' => 'Postal Code · Code Postale',
'Phone' => 'Phone · Téléphone',
'Pay Now' => 'Pay Now · Payer maintenant',
'We\'re sorry, but all ticket sales have ended.' => 'We\'re sorry, but the deadline for registrations is past. · Nous sommes désolés, mais la date limite pour les inscriptions est passée.',
// Add some more strings here
);
// See if the current string is in the $strings array
// If so, replace its translation
if ( isset( $strings[$original] ) ) {
// This accomplishes the same thing as __()
// but without running it through the filter again
$translations = get_translations_for_domain( $domain );
$translated = $translations->translate( $strings[$original] );
}
return $translated;
}
add_filter( 'gettext', 'ee_general_filter_gettext', 10, 3 );
/**
* ------------------------------------------------------------------------
//* EVENT ESPRESSO FILTER OUT ALREADY STARTED MULTI DATETIME EVENTS:
* ------------------------------------------------------------------------
*/
/**
* The purpose of this snippet is to filter the event archive (and event taxonomy archive) pages so that they exclude events
* that have tickets no longer on sale.
*
* NOTE: This query is only valid for Event Espresso 4.8+
*
* To Implement this code, add it to the bottom of your themes functions.php file, or add it to a site specific plugin.
*
*/
function de_ee_tweak_event_list_exclude_ticket_expired_events_where( $SQL, WP_Query $wp_query ) {
if ( isset( $wp_query->query_vars['post_type'] ) && ( $wp_query->query_vars['post_type'] == 'espresso_events' || ( is_array( $wp_query->query_vars['post_type'] ) && in_array( 'espresso_events', $wp_query->query_vars['post_type'] ) ) ) && ! $wp_query->is_singular ) {
$SQL .= ' AND Ticket.TKT_end_date > "' . current_time( 'mysql', true ) . '" AND Ticket.TKT_deleted=0';
}
return $SQL;
}
add_filter( 'posts_where', 'de_ee_tweak_event_list_exclude_ticket_expired_events_where', 15, 2 );
function de_ee_tweak_event_list_exclude_ticket_expired_events_join( $SQL, $wp_query ) {
if ( isset( $wp_query->query_vars['post_type'] ) && ( $wp_query->query_vars['post_type'] == 'espresso_events' || ( is_array( $wp_query->query_vars['post_type'] ) && in_array( 'espresso_events', $wp_query->query_vars['post_type'] ) ) ) && ! $wp_query->is_singular ) {
if ( ! $wp_query->is_espresso_event_archive && ! $wp_query->is_espresso_event_taxonomy ) {
$SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table() . '.ID = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name() . ' ) ';
}
$SQL .= ' INNER JOIN ' . EEM_Datetime_Ticket::instance()->table() . ' AS Datetime_Ticket ON ( Datetime_Ticket.DTT_ID=' . EEM_Datetime::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name() . ' ) INNER JOIN ' . EEM_Ticket::instance()->table() . ' AS Ticket ON ( Datetime_Ticket.TKT_ID=Ticket.' . EEM_Ticket::instance()->primary_key_name() . ' ) ';
}
return $SQL;
}
add_filter( 'posts_join', 'de_ee_tweak_event_list_exclude_ticket_expired_events_join', 3, 2 );
/* Stop Adding Functions */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment