Your address will show here +12 34 56 78

Home Forums WP RESIDENCE – Real Estate WordPress Theme FORUM If you need to display price range instead of single price

This topic contains 4 replies, has 4 voices, and was last updated by  1dnmr 2 years, 2 months ago.

  • Author
    Posts
  • #107554

    1dnmr
    Participant

    Hi,

    Here is the solution.
    1. Add custom fields “price mix”, “price max”

    2. Put this function to you local functions.php

    
    /////////////////////////////////////////////////////////////////////////////////
    // show price range
    ///////////////////////////////////////////////////////////////////////////////////
    
    function wpestate_show_price_range($post_id,$currency,$where_currency,$return=0){
          
        $price_label    = '<span class="price_label">'.esc_html ( get_post_meta($post_id, 'property_label', true) ).'</span>';
    
        $price_from     = intval( get_post_meta($post_id, 'min-price', true) );
        $price_to       = intval( get_post_meta($post_id, 'max-price', true) );            
        
        $th_separator   =get_option('wp_estate_prices_th_separator','');
        $custom_fields = get_option( 'wp_estate_multi_curr', true);
        //print_r($_COOKIE);
        if( !empty($custom_fields) && isset($_COOKIE['my_custom_curr']) &&  isset($_COOKIE['my_custom_curr_pos']) &&  isset($_COOKIE['my_custom_curr_symbol']) && $_COOKIE['my_custom_curr_pos']!=-1){
            $i=intval($_COOKIE['my_custom_curr_pos']);
            $custom_fields = get_option( 'wp_estate_multi_curr', true);
            if ($price_from != 0) {
                $price_from      = $price_from * $custom_fields[$i][2];
                $price_from      = number_format($price_from,0,'.',$th_separator);
               
                $currency   = $custom_fields[$i][0];
                
                if ($custom_fields[$i][3] == 'before') {
                    $price_from = $currency . $price_from;
                } else {
                    $price_from = $price_from . $currency;
                }
                
            }else{
                $price_from='';
            }
    
            if ($price_to != 0) {
                $price_to      = $price_to * $custom_fields[$i][2];
                $price_to      = number_format($price_to,0,'.',$th_separator);
               
                $currency   = $custom_fields[$i][0];
                
                if ($custom_fields[$i][3] == 'before') {
                    $price_to = $currency . $price_to;
                } else {
                    $price_to = $price_to . $currency;
                }
                
            }else{
                $price_to='';
            }
    
        }else{
            if ($price_from != 0) {
               $price_from = number_format($price_from,0,'.',$th_separator);
    
                if ($where_currency == 'before') {
                    $price_from = $currency . $price_from;
                } else {
                    $price_from = $price_from . $currency;
                }
                
            }else{
                $price_from='';
            }
    
            if ($price_to != 0) {
               $price_to = number_format($price_to,0,'.',$th_separator);
    
                if ($where_currency == 'before') {
                    $price_to = $currency . $price_to;
                } else {
                    $price_to = $price_to . $currency;
                }
                
            }else{
                $price_to='';
            }
    
        }
        
      
        
        if($return==0){
            print $price_from.' - '.$price_to.' '.$price_label;
        }else{
             return $price_from.' - '.$price_to.' '.$price_label;
        }
    }
    
    /////////////////////////////////////////////////////////////////////////////////
    // show price range
    ///////////////////////////////////////////////////////////////////////////////////
    
    

    3. Use in single-estate_property.php template like this

    
      <div class=" <?php print $options['content_class'];?> ">
            <?php get_template_part('templates/ajax_container'); ?>
            <?php
            while (have_posts()) : the_post();
                $price          =   intval   ( get_post_meta($post->ID, 'property_price', true) );
                $price_from     =   esc_html( get_post_meta($post->ID, 'min-price', true) );
                $price_to       =   esc_html( get_post_meta($post->ID, 'max-price', true) );            
                $price_label    =   esc_html ( get_post_meta($post->ID, 'property_label', true) );  
                $image_id       =   get_post_thumbnail_id();
                $image_url      =   wp_get_attachment_image_src($image_id, 'property_full_map');
                $full_img       =   wp_get_attachment_image_src($image_id, 'full');
                $image_url      =   $image_url[0];
                $full_img       =   $full_img [0];    
                if ($price_from != 0 && $price_to != 0) {
                    $price = wpestate_show_price_range(get_the_ID(),$currency,$where_currency,1);   
                } 
                else if ($price != 0) {
                   $price = wpestate_show_price(get_the_ID(),$currency,$where_currency,1);  
                }else{
                   $price='';
                }
            ?>
    
    • This topic was modified 2 years, 2 months ago by  Anna.
  • #109090

    Thank you for deciding to share your solution with other clients. That’s very kind of you. Camelia

  • #115823

    gaurav
    Participant

    can you please share link of page where you have implemented this code.

  • #117256

    tystra
    Participant

    I would also love to see a page where this is displayed, thanks in advance!

  • #117258

    1dnmr
    Participant

    Hi guys,

    Here the page example http://villasonsamui.ru/properties/villa-beige/
    Tell the truth I spend two month customising the theme. many code rewrote, many new added. Original theme has HUGE count of minor defects in CSS, especially when you want to see you theme truly responsive.

    • This reply was modified 2 years, 2 months ago by  Anna.

You must be logged in to reply to this topic.