Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Last active January 9, 2020 12:23
Show Gist options
  • Select an option

  • Save Pebblo/f952f806aec55df5f8a1 to your computer and use it in GitHub Desktop.

Select an option

Save Pebblo/f952f806aec55df5f8a1 to your computer and use it in GitHub Desktop.
This is an example of how you can add payment methods to the available payment methods on the front end for admin users only. This function will add the 'Invoice' payment method that admins can select on the front end of the site, (any user without the 'manage_options' cap will not see the PM). This is useful for allowing users to use Multi Even…
<?php
/*
Plugin Name: Event Espresso site specific functions
Description: Add custom functions for Event Espresso to this plugin.
/* Begin Adding Functions Below This Line; Do not include an opening PHP tag as this sample code already includes one! */
function tw_ee_output_admin_invoice_payment_method($payment_methods, $transaction, $scope) {
//Check if the user is logged in, is not within the admin and has the correct capability
if( is_user_logged_in() && current_user_can( 'manage_options' ) ) {
//Check we are within SPCO
$checkout = EE_Registry::instance()->SSN->checkout();
if ( $checkout instanceof EE_Checkout ) {
//Sanity check to check we have a valid EE_Transaction object
if ( $transaction instanceof EE_Transaction) {
//Pull in an Invoice payment method.
$invoice_payment_method = EEM_Payment_Method::instance()->get_one_of_type( 'Invoice' );
//Check we actually have an EE_Payment_Method object and add it to the payment methods.
if( $invoice_payment_method instanceof EE_Payment_Method ) {
$payment_methods[] = $invoice_payment_method;
}
}
}
}
return $payment_methods;
}
add_filter('FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', 'tw_ee_output_admin_invoice_payment_method', 10, 3 );
@Pebblo
Copy link
Copy Markdown
Author

Pebblo commented Nov 9, 2016

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