Plugin for TheCartPress: Currency Symbol

We are going to show how to make this simple plugin, but useful, for TheCartPress.

The plugin allows to display the currency code instead of the ISO code of the eCommerce currency. Since version 1.0.8 of TheCartPress this plugin is built into the eCommerce software.

See how to make it:
First step: Create a folder called ‘thecartpress-currency-symbol’, in the wp-content/plugins folder.
Second step: Create a file called CurrencySymbol.class.php into the new folder and write this code:

<?php
/*
Plugin Name: TheCartPress Currency Symbol
Plugin URI: http://thecartpress.com
Description: Display currency symbol
Version: 1.0
Author: TheCartPress team
Author URI: http://thecartpress.com
License: GPL
Parent: thecartpress
*/

/**
 * This file is part of TheCartPress Currency Symbol.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;

if ( ! class_exists( 'CurrencySymbol' ) ) :

class CurrencySymbol {
	function __construct() {
		if ( ! is_admin() ) {
			add_filter( 'tcp_the_currency', array( $this, 'tcp_the_currency' ) );
		}
	}

	function tcp_the_currency( $currency ) {
		if ( $currency == 'EUR' ) {
			return '&euro;';
		} elseif ( $currency == 'USD' ) {
			return '$';
		} elseif ( $currency == 'GBP' ) {
			return '&pound;';
		} elseif ( $currency == 'JPY' ) {
			return '&yen;';
		} else {
			return $currency;
		}
	}
}

new CurrencySymbol();
endif; // class_exists check

This code should be saved in a file called ‘CurrencySymbol.class.php’ into the folder ‘thecartpress-currency-symbol’.

Explanation of code:

From line 1 to 10 the WordPress area to identify the plugin,
From line 12 to 27 the license,
Line 32: We want to apply a filter in the constructor of the class. The filter ‘tcp_the_currency‘ is executed when the tcp_get_the_currency template function is called,
From line 36 to 47 the plugin returns the currency symbol depending on the currency iso.

And that’s all.