Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshfeck/d53bbbb8358083f5047e8683d6ec14b2 to your computer and use it in GitHub Desktop.
Save joshfeck/d53bbbb8358083f5047e8683d6ec14b2 to your computer and use it in GitHub Desktop.
Example code that shows how to add a new transaction shortcode for use in Event Espresso 4's invoice template
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
function register_new_example_transaction_shortcode( $shortcodes, EE_Shortcodes $lib ) {
if ( $lib instanceof EE_Transaction_Shortcodes ) {
//Add your shortcode to add as the key, the value should be a description of the shortcode.
$shortcodes['[RECALCULATED_SURCHARGE_AFTER_PROMOTION]'] = _('This is the recalculated surcharge amount after promotion is applied');
}
//Return the shortcodes.
return $shortcodes;
}
add_filter( 'FHEE__EE_Shortcodes__shortcodes', 'register_new_example_transaction_shortcode', 10, 2 );
function register_new_example_transaction_shortcode_parser( $parsed, $shortcode, $data, $extra_data, EE_Shortcodes $lib ) {
if ( $lib instanceof EE_Transaction_Shortcodes && $data->txn instanceof EE_Transaction ) {
if ( $shortcode == '[RECALCULATED_SURCHARGE_AFTER_PROMOTION]' ) {
$txn = $data->txn instanceof EE_Transaction ? $data->txn : null;
if($txn==null){
return;
}
if(!$txn->line_items(array(array('OBJ_type' => 'Promotion')))){
return;
}
$total = $txn->total();
return number_format($total-($total/1.19), 2);
}
}
//Return the currently parsed content.
return $parsed;
}
add_filter( 'FHEE__EE_Transaction_Shortcodes__parser_after', 'register_new_example_transaction_shortcode_parser', 10, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment