JoeHana
8/21/2013 - 12:41 AM

Add Price after Sold/Rented in Property Overview

Add Price after Sold/Rented in Property Overview

<?php

/**
 * Add Price after Sold/Rented in Property Overview
 */
 
add_filter('wpcasa_property_price', 'custom_property_price');

function custom_property_price($property_price) {
    
	// Get post ID from $post_id

	if( empty( $post_id ) )
		$post_id = get_the_ID();	
	
	// If still empty, return false
	
	if( empty( $post_id ) )
		return false;
		
	// Set property price labels
	
	$property_price_labels = array(
		'sold' 	  => __( 'Property is sold', 'wpcasa'  ),
		'rented'  => __( 'Property is rented', 'wpcasa'  ),
		'request' => __( 'Price on request', 'wpcasa'  )
	);
	
	$property_price_labels = apply_filters( 'wpcasa_get_price_labels', $property_price_labels );
		
	// Get property price
	$property_price = wpcasa_get_price_value();
		
	// Get custom fields
		
	$custom_fields 			= get_post_custom( $post_id );
	$property_status 		= $custom_fields['_price_status'][0];
	$property_availability 	= isset( $custom_fields['_price_sold_rented'][0] ) ? $custom_fields['_price_sold_rented'][0] : false;
	
	// Create price output
	
	if( ! empty( $property_availability ) ) {
	
		// When property is not available
		
		$sold_rented = ( $property_status == 'sale' ) ? $property_price_labels['sold'] : $property_price_labels['rented'];
		
		$property_price = '<span class="property-price-sold-rented">' . $sold_rented . '<br />' . wpcasa_get_price_value() . '</span><!-- .property-price-sold-rented -->';
		
		if( is_admin() )
			$property_price .= '<br />' . wpcasa_get_price_value();
		
	} elseif( empty( $property_price ) ) {
		
		// When no price available Price on request
		$property_price = '<span class="property-price-on-request">' . $property_price_labels['request'] . '</span><!-- .property-price-on-request -->';
	
	}
	
	return $property_price;
}