Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save geekontheroad/ca4270c45129cd7d11ad9e04509d31c0 to your computer and use it in GitHub Desktop.
Save geekontheroad/ca4270c45129cd7d11ad9e04509d31c0 to your computer and use it in GitHub Desktop.
<?php // don't copy this first line
/**
* This snippet is written for the Gravity EU VAT plugin ( https://geekontheroad.com/eu-vat-for-gravity-forms )
* It allows you to overwrite the default country information on a form basis. This overwrites the default tax country set in the settings
* This snippet is compatible with GF EU VAT v1.0.8.2 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.2
* @author Johan d'Hollander
* @link <https://geekontheroad.com>
*
**/
class GOTREU_Form_Default_Tax_Country {
public function __construct($args = array()) {
$this->_args = wp_parse_args($args, array(
"form_id" => null,
"iso_code" => '',
"standard_rate" => ''
));
if (!is_null($this->_args["form_id"]) && $this->_args["form_id"] !== '') {
add_filter( "gotreu_default_tax_country_info_" . $this->_args["form_id"], array($this , "change_default_country") , 10 , 2 );
}
}
public function change_default_country( $tax_info , $form_id ) {
if(!class_exists("Gotreu_Tax_Rates")) {
return $tax_info;
}
$country_code = $this->_args["iso_code"];
if( Gotreu_Tax_Rates::getCountryDetails($country_code) !== false ) {
return array(
$country_code,
is_numeric($this->_args["standard_rate"]) ? $this->_args["standard_rate"] : Gotreu_Tax_Rates::getStandardRate( $country_code , $form_id ),
);
}
return $tax_info;
}
}
// Required Configuration
new GOTREU_Form_Default_Tax_Country( array(
"form_id" => 2, // the form Id where you want to change the default tax country
"iso_code" => "FR", // the 2 digit ISO code of the country. For example: FR for France
"standard_rate" => "20" // use this to overwrite the standard rate for this country. Leave empty to use default
) );
// OPTIONAL
// Want to apply this to a second form?
// Just copy past the above configuration bit only and change the form ID
new GOTREU_Form_Default_Tax_Country( array(
"form_id" => 6, // the form Id where you want to change the default tax country
"iso_code" => "FR", // the 2 digit ISO code of the country. For example: FR for France
"standard_rate" => "20" // use this to overwrite the standard rate for this country. Leave empty to use default
) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment