Support

Home Forums Translations New currencies in organization_config.php

New currencies in organization_config.php

Posted: August 26, 2013 at 4:56 am


Cristi Constantin

August 26, 2013 at 4:56 am

Hi,

Is it possible that you include RON as Romanian currency, in orgarnization_config.php?
The code to add:

<pre class=”brush: php; gutter: true; first-line: 1; highlight: []; html-script: false”>
case 'ROM' : $org_options['currency_symbol'] = 'RON'; // Romanian leu
break;


Cristi Constantin

August 26, 2013 at 4:57 am

<pre class=”brush: php; gutter: true; first-line: 1; highlight: []; html-script: false”> case 'ROM' : $org_options['currency_symbol'] = 'RON'; // Romanian leu
break;


Cristi Constantin

August 26, 2013 at 5:03 am

Sorry for not being able to format the code. Actually, it should display ‘lei’ instead of ‘RON’. Thank you.


Cristi Constantin

August 26, 2013 at 5:04 am

Final form, while checking other important romanian sites: Lei (with uppercase L)


Cristi Constantin

August 26, 2013 at 5:07 am

Also, not all currencies are supposed to be displayed as prefix, but should be as a suffix, and also with a “space” character. E.g.:
-wrong: Lei23.85
-wrong: 23.85Lei
-right: 23.85 Lei


Dean

August 27, 2013 at 12:31 am

Hi Christi,

I can certainly request the addition, though when or if it will be added I cannot confirm.

From initial looks, I believe at some point in the 4.X series users will have more control over the currency structure, including placement of the currency symbol/code.


Cristi Constantin

September 11, 2013 at 6:09 am

What is the recommended way to preserve my custom block code, in case of EE plugin updates, if this is part of /includes/organization_settings.php, organization_config_mnu() function ?
Thanks.


Josh

  • Support Staff

September 11, 2013 at 11:06 am

I can advise not adding the new currency to organization_config.php. Instead you can use a custom function and place it inside /wp-content/uploads/espresso/custom_functions.php:

function my_change_ee_currency( $content ) {

	global $org_options;

	$base = $org_options['currency_symbol'];

	$replace = '<span class="currency">Lei</span>';

	$content = str_replace( $base, $replace, $content );

	return $content;

}

add_filter( 'the_content', 'my_change_ee_currency', 11 );

This will do two things:

1) Do a string replace and display your currency is display

2) wrap the currency letters in a span tag with a class of “currency” to allow positioning it to the right side of the price value with CSS.


Cristi Constantin

September 12, 2013 at 1:06 am

Nice idea, I start to understand how to customize these aspects. But:
no. 2) – right alinment of currency – does it need some CSS code somewhere? for me, it still gets displayed to the left of the numeric value; in html code, the result is like this:

<code>&lt;p id=&quot;p_event_price-2&quot; class=&quot;event_price&quot;&gt;
&lt;span class=&quot;section-title&quot;&gt;Price: &lt;/span&gt;
&lt;span class=&quot;currency&quot;&gt;Lei&lt;/span&gt;12.00&lt;/p&gt;</code>

Secondly, the ‘the_content’ filter hook works for any EE aspect? like the following content types:

email
invoice
EE mobile app

Wouldn’t it be better to write some init hook as to set the
$org_options['currency_symbol'] = 'Lei'


Dean

September 17, 2013 at 3:33 am

Hi,

I would say that you would most likely need to edit the template files, for instance, in the event list the price is shown via this code

event_cost; ?>

swapping the position of the $org_options[‘currency_symbol’] and the event cost will display them the way you want to.

Due to the way the plugin is made, you will need to do this in both the event_list_display.php and registration_page_display.php but there may be other places as well, tickets and invoice for example.

the_content is WordPress core so it will affect only post and pages to my knowledge

Wouldn’t it be better to write some init hook

I believe we are looking at making it easier for international users to modify the cost structure at some point in version 4, as we know the standard UK/US format isn’t ideal for the rest of the world.


Cristi Constantin

September 22, 2013 at 1:02 am

Let’s say that for this stage I would be satisfied to set the $org_options['currency_symbol']. How could I do this from an action hook? I was thinking that, at least when I save the settings of my custom payment gateway, I could set the property to Lei.


Josh

  • Support Staff

September 23, 2013 at 11:03 am

Hi Cristi,

I don’t believe the currency options can be changed via an action hook.

To follow up with your CSS question, yes, you can use the classname in the example code to float the span right/left or position it to your specifications.


Cristi Constantin

September 23, 2013 at 3:33 pm

Currently adopted solution for setting the currency (no CSS yet) and covering all relevant places, was to add to my custom gateway, in settings.php, that when the gateway settings are saved, then the currency is set accordingly:

<code>		// set Lei as currency
		$org_options = get_option(&#039;events_organization_settings&#039;);
		$org_options[&#039;currency_symbol&#039;] = &#039; Lei &#039;;
		update_option(&#039;events_organization_settings&#039;, $org_options);</code>

I will check the CSS span feature sometime later.


Dean

September 24, 2013 at 3:40 am

Thanks for sharing your solution.


Cristi Constantin

September 26, 2013 at 7:48 am

There is still a problem, that whenever I save the organization settings, it puts again the $ sign as currency… I would really like to settle this somehow, without altering EE core php pages…


Josh

  • Support Staff

September 26, 2013 at 9:48 pm

You can avoid altering core Event Espresso functions and use your specified currency by using the custom function I suggested in this post:

https://eventespresso.com/topic/new-currencies-in-organization_config-php/#post-58767

Then you can use your currency within the gateway (and avoid using the currency set in Event Espresso>General options).


Cristi Constantin

September 29, 2013 at 10:56 am

All the solutions mentioned so for do not cover both requirements:
1. do not alter EE core code;
2. affect all places where the currency is relevant, with minimal coding and 100% guarantee: posts, invoice, emails, etc.

As a result, I had to investigate further so here is the solution which _really_ works for setting ‘Lei ‘ currency (no CSS manipulation yet).
The following code has been added to custom_functions.php.

<pre class=”brush: php; gutter: true; first-line: 1; highlight: []; html-script: false”><?php

/*
Description: This function sets 'Lei ' as Event Espresso currency, if the selected country is Romania
*/
function RON_currency_for_Romania( $newvalue, $oldvalue )
{

$currency_format = getCountryFullData($newvalue['organization_country']);

if (strcasecmp($currency_format['iso_code_3'], 'ROM') == 0)
$newvalue['currency_symbol'] = 'Lei ';

return $newvalue;
}

add_filter('pre_update_option_events_organization_settings', 'RON_currency_for_Romania', 10, 2);


Cristi Constantin

September 30, 2013 at 12:40 am

The right alignment of the currency symbol was solved using php regular expression replace, covering posts and pages. Invoice and email will be treated separately. The following code has been added to custom_functions.php.

/*
Description: aligns the currency symbol to the right of the value itself; applies for posts and pages, where ‘the_content’ makes sense
*/
function align_currency_right( $content ) {

global $org_options;

$base = $org_options[‘currency_symbol’];

$content = preg_replace( ‘/(‘ . $base . ‘) *([0-9.,]+)/’, ‘$2 $1’, $content );

return $content;

}

add_filter( ‘the_content’, ‘align_currency_right’, 11);

The support post ‘New currencies in organization_config.php’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso