Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Created February 4, 2014 15:59
Show Gist options
  • Select an option

  • Save strangerstudios/8806443 to your computer and use it in GitHub Desktop.

Select an option

Save strangerstudios/8806443 to your computer and use it in GitHub Desktop.
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.
/*
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");
@catchkomal
Copy link

though this is not complete tested code this way we don't have to manage new level as customization with level id might be there in pmpro customization plugin

@andrewlimaza
Copy link

You can also try this plugin (maintained by a developer outside of PMPro) -> https://wordpress.org/plugins/pmpro-multiple-currencies/

@catchkomal
Copy link

this plugin also have same issue we need to create new level the solution which i gave is more wise then creating new level the whole idea is to maintain different price as per the currency at same level id

@catchkomal
Copy link

@andrewlimaza whole idea here is if the geo location is Nigeria then charge as per Naira and if the geo location is Liverpool suppose then charge as GBP

@catchkomal
Copy link

I can improvise it further once my all test goes perfect @andrewlimaza but solution that you gave is not much helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment