Change currency case-by-case @decorum
This code snippet makes it possible to change the currency on a case-by-case base. By creating a new custom field (either currency_alt or currency_alt2) the value will override the default settings.
<?php
/**
* Change currency case-by-case
*/
add_filter( 'ts_currency', 'custom_currency' );
function custom_currency( $currency ) {
// get field values
$alt1 = get_post_meta( get_the_ID(), 'currency_alt', true );
$alt2 = get_post_meta( get_the_ID(), 'currency_alt2', true );
// set additional currencies
$currency_alt1 = 'THB';
$currency_alt2 = 'EUR';
// return based on setting
if( $alt1 ) {
return $currency_alt1;
} elseif( $alt2 ) {
return $currency_alt2;
} else {
return $currency;
}
}
add_filter( 'ts_currency_entity', 'custom_currency_entity' );
function custom_currency_entity( $entity ) {
// get field values
$alt1 = get_post_meta( get_the_ID(), 'currency_alt', true );
$alt2 = get_post_meta( get_the_ID(), 'currency_alt2', true );
// set additional currency-entities
$currency_entity_alt1 = '฿';
$currency_entity_alt2 = '€';
// return based on setting
if( $alt1 ) {
return $currency_entity_alt1;
} elseif( $alt2 ) {
return $currency_entity_alt2;
} else {
return $entity;
}
}