Skip to content

Instantly share code, notes, and snippets.

@usmanaliqureshi
Last active May 22, 2020 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usmanaliqureshi/2aa15f498cc419467b0bdae95b18c396 to your computer and use it in GitHub Desktop.
Save usmanaliqureshi/2aa15f498cc419467b0bdae95b18c396 to your computer and use it in GitHub Desktop.
Add discounted price to each property in Real Homes Theme
/**
* Discounted Price CSS
**/
.striked_price {
text-decoration: line-through;
margin-right: 10px;
font-size: 18px;
color: red !important;
}
.discounted {
color: #ea723d;
}
.single-property .rh_property__meta:last-child {
display: none;
}
<?php
/**
* Add property discounted price
*/
function add_property_custom_fields( $new_fields ) {
$new_fields['tab'] = array(
'label' => 'Discounted Price', // tab name
'icon' => 'dashicons-admin-generic' // tab icon class (of dashicon). See all dashicons here: https://developer.wordpress.org/resource/dashicons
);
$new_fields['fields'] = array(
array(
'id' => 'discounted_price', // Unique id for the custom field
'name' => 'Discounted Price', // field name
'desc' => 'Only numbers', // field description
'postfix' => '', // field postfix (if any)
'icon' => 'price', // Place “png” icon in "realhomes/assets/(variation you are using)/icons" directory. Retina (double sized) icons should use @2x as postfix with icon name. E.g: year.png, year@2x.png
'columns' => 6, // use ‘6’ for two fields in one row and ’12’ for one field in one row
'display' => true // true to display field value on property detail page, otherwise false
),
);
return $new_fields;
}
add_filter( 'inspiry_property_custom_fields', 'add_property_custom_fields' );
function inspiry_show_discounted_price( $formatted_price ) {
$currency = ere_get_currency_sign();
$discounted_price = doubleval( get_post_meta( get_the_ID(), 'REAL_HOMES_discounted_price', true ) );
if ( empty( $discounted_price ) ) {
return $formatted_price;
} else {
$formatted_discounted_price = ( empty( $discounted_price ) ) ? '' : $currency . '' . number_format( $discounted_price );
return "<span class='striked_price'>" . $formatted_price . "</span> <span class='discounted'>" . $formatted_discounted_price . "</span>";
}
}
add_filter( 'inspiry_property_price', 'inspiry_show_discounted_price', 10, 2 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment