Forked from strangerstudios/update_currency_per_level.php
Created
February 19, 2014 10:50
-
-
Save cyberwani/9089730 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Change currencies depending on Paid Memberships Pro level. | |
Add this code to your active theme's functions.php or a custom plugin. | |
This is just an example that will need to be tweaked for your needs. | |
Other places to look into swapping currencies: | |
* Levels page. | |
* Invoices page. | |
* In emails. | |
* In membership levels table in admin. | |
* When using discount codes. | |
*/ | |
/* | |
Global to store levels with non-default currencies | |
Keys are level ids. Values are an asrray with the currency abbreviation and symbol as the first and second entries. | |
*/ | |
global $level_currencies; | |
$level_currencies = array( | |
5 => array("EUR", "€"), | |
6 => array("GBP", "£") | |
); | |
//main function to check for a currency level and update currencies | |
function update_currency_per_level($level_id) | |
{ | |
global $pmpro_currency, $pmpro_currency_symbol, $level_currencies; | |
foreach($level_currencies as $level_currency_id => $level_currency) | |
{ | |
if($level_id == $level_currency_id) | |
{ | |
$pmpro_currency = $level_currency[0]; | |
$pmpro_currency_symbol = $level_currency[1]; | |
} | |
} | |
} | |
//change currency on checkout page | |
function my_pmpro_checkout_level($level) | |
{ | |
update_currency_per_level($level->id); | |
return $level; | |
} | |
add_filter("pmpro_checkout_level", "my_pmpro_checkout_level"); | |
//change currency when sent as a request param | |
function my_init_currency_check() | |
{ | |
if(!empty($_REQUEST['level'])) | |
return update_currency_per_level(intval($_REQUEST['level'])); | |
} | |
add_action("init", "my_init_currency_check"); | |
//params in the admin | |
function my_admin_init_currency_check() | |
{ | |
if(!empty($_REQUEST['edit']) && !empty($_REQUEST['page']) && $_REQUEST['page'] == 'pmpro-membershiplevels') | |
return update_currency_per_level(intval($_REQUEST['edit'])); | |
} | |
add_action("admin_init", "my_admin_init_currency_check"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment