Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save geekontheroad/d7b67803f58b3cd83d1d4c73a3c214fd to your computer and use it in GitHub Desktop.
Save geekontheroad/d7b67803f58b3cd83d1d4c73a3c214fd to your computer and use it in GitHub Desktop.
<?php // dont copy this line
/**
* This snippet is written for the Gravity EU VAT plugin ( https://geekontheroad.com/eu-vat-for-gravity-forms )
* It allows you to apply reverse charge tax for valid tax number of the default country
* This snippet is compatible with GF EU VAT v1.0.8.3 and higher
*
* INSTRUCTIONS:
* Copy/Paste the below code to your functions.php or code snippet plugin
* Complete the configuration part at the bottom of this code
*
* @version 0.3
* @author Johan d'Hollander
* @link <https://geekontheroad.com>
*
**/
class GOTREU_Enable_Default_Country_Reverse_Charge {
public function __construct($args = array()) {
$this->_args = wp_parse_args($args, array(
"form_ids" => [], // Change to expect an array
));
add_action('wp_footer', array($this, 'register_init_script'), 99);
}
public function register_init_script() {
if (empty($this->_args['form_ids'])) return; // Exit if no form IDs are set
// Convert form IDs to JSON for use in JavaScript
$form_ids_json = json_encode($this->_args['form_ids']);
?>
<script type="text/javascript">
gform.addFilter('gotreu_default_country_reverse_charge', 'gotreu_enable_reverse_charge');
function gotreu_enable_reverse_charge(isDefaultCountry, formId) {
var formIdStr = String(formId);
var targetFormIds = <?php echo $form_ids_json; ?>.map(String);
if (targetFormIds.includes(formIdStr)) {
return false;
}
return isDefaultCountry;
}
</script>
<?php
}
}
// Required Configuration
new GOTREU_Enable_Default_Country_Reverse_Charge(array(
"form_ids" => [2, 6], // Enter an array of form ids Example: [1,2,3,4]
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment