Plugin for TheCartPress: Unavailable item

This plugin allows to display the “UNAVAILABLE ” label instead of showing prices for no stock items.

<?php
/*
Plugin Name: TheCartPress Unavailable item
Plugin URI: http://thecartpress.com
Description: Display Unavailable label for no stock items
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( 'TCPUnavailableItem ' ) ) :
class TCPUnavailableItem {
	function __construct() {
		if ( ! is_admin() ) {
			add_filter( 'tcp_get_the_price_label', array( $this, 'tcp_get_the_price_label' ), 10, 3 ); 
		}
	}

	function tcp_get_the_price_label( $label, $post_id, $price ) {
		if ( tcp_get_the_stock( $post_id ) == 0 ) {
			return __( 'UNAVAILABLE' ); //TODO add language support
		} else {
			return $label;
		}
	}
}

new TCPUnavailableItem();
endif; // class_exists check

This code should be saved in a file called ‘UnavailableItem.class.php’ into a folder called ‘thecartpress-unavailable-item ‘.

And that’s all.