JoeHana
7/11/2013 - 10:39 PM

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 ne

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 = '&#3647;';
    $currency_entity_alt2 = '&#8364;';
	
    // return based on setting    
	if( $alt1 ) {
	    return $currency_entity_alt1;
    } elseif( $alt2 ) {
        return $currency_entity_alt2;
    } else {
        return $entity;
    }
			
}