Skip to content

Instantly share code, notes, and snippets.

@deckchairuk
Last active April 18, 2017 14:00
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 deckchairuk/3edc13ff8c0c0d852a4828045e432594 to your computer and use it in GitHub Desktop.
Save deckchairuk/3edc13ff8c0c0d852a4828045e432594 to your computer and use it in GitHub Desktop.
<?php
function register_vat_shortcode( $shortcodes, EE_Shortcodes $lib ) {
if ( $lib instanceof EE_Transaction_Shortcodes ) {
$shortcodes['[VAT_PAID]'] = _('This calculates 20% of the total price, to find out how much of what was paid is VAT.');
}
return $shortcodes;
}
add_filter( 'FHEE__EE_Shortcodes__shortcodes', 'register_vat_shortcode', 10, 2 );
function register_vat_shortcode_parser( $parsed, $shortcode, $data, $extra_data, EE_Shortcodes $lib ) {
if ( $lib instanceof EE_Transaction_Shortcodes ) {
$transaction = $data->txn instanceof EE_Transaction ? $data->txn : null;
$transaction = ! $transaction instanceof EE_Transaction && is_array( $extra_data ) && isset( $extra_data['data'] ) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data']->txn: $transaction;
if ( $shortcode == '[VAT_PAID]' ) {
$vat_total = $transaction->total() * 0.2;
return ! empty($vat_total) ? EEH_Template::format_currency( $vat_total ) : '';
}
}
return $parsed;
}
add_filter( 'FHEE__EE_Shortcodes__parser_after', 'register_vat_shortcode_parser', 10, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment