/**
  *	rental_periods_register()
  *	
  *	Register rental periods
  *	for Polylang strings translation.
  *	
  *	@uses	wpsight_rental_periods()
  *	@uses	wpsight_get_rental_period()
  *	@uses	pll_register_string()
  *	
  *	@since 1.0.0
  */
 public function rental_periods_register()
 {
     $periods = wpsight_rental_periods();
     foreach ($periods as $period => $label) {
         $rental_period = wpsight_get_rental_period($period);
         pll_register_string('Listing Periods', $rental_period, WPSIGHT_NAME);
     }
 }
Exemple #2
0
 /**
  * Register rental periods to be translatable by WPML
  */
 function wpsight_wpml_rental_periods_register()
 {
     if (!function_exists('icl_register_string')) {
         return false;
     }
     $periods = wpsight_rental_periods();
     foreach ($periods as $period => $label) {
         $rental_period = wpsight_get_rental_period($period);
         icl_register_string(WPSIGHT_NAME . ' - ' . __('Rental Periods', 'wpsight-wpml'), $period, $rental_period);
     }
     return false;
 }
Exemple #3
0
 function wpsight_get_price_value($post_id = '', $number_format = true, $currency = true, $show_period = true)
 {
     // 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;
     }
     // Get custom fields
     $custom_fields = get_post_custom($post_id);
     $listing_price = isset($custom_fields['_price'][0]) ? $custom_fields['_price'][0] : false;
     $listing_status = isset($custom_fields['_price_status'][0]) ? $custom_fields['_price_status'][0] : false;
     $rental_period = isset($custom_fields['_price_period'][0]) ? $custom_fields['_price_period'][0] : false;
     // Return false if no price
     if (empty($listing_price)) {
         return false;
     }
     if ($number_format == true) {
         $listing_price_arr = false;
         // Remove white spaces
         $listing_price = preg_replace('/\\s+/', '', $listing_price);
         if (strpos($listing_price, ',')) {
             $listing_price_arr = explode(',', $listing_price);
         }
         if (strpos($listing_price, '.')) {
             $listing_price_arr = explode('.', $listing_price);
         }
         if (is_array($listing_price_arr)) {
             $listing_price = $listing_price_arr[0];
         }
         // remove dots and commas
         $listing_price = str_replace('.', '', $listing_price);
         $listing_price = str_replace(',', '', $listing_price);
         if (is_numeric($listing_price)) {
             // Get thousands separator
             $listing_price_format = wpsight_get_option('currency_separator', true);
             // Add thousands separators
             if ($listing_price_format == 'dot') {
                 $listing_price = number_format($listing_price, 0, ',', '.');
                 if (is_array($listing_price_arr)) {
                     $listing_price .= ',' . $listing_price_arr[1];
                 }
             } else {
                 $listing_price = number_format($listing_price, 0, '.', ',');
                 if (is_array($listing_price_arr)) {
                     $listing_price .= '.' . $listing_price_arr[1];
                 }
             }
         }
     }
     // endif $number_format
     // Get currency symbol and place before or after value
     $currency_symbol = wpsight_get_option('currency_symbol', true);
     // Create price markup and place currency before or after value
     if ($currency_symbol == 'after') {
         $listing_price_symbol = '<span class="listing-price-value">' . $listing_price . '</span><!-- .listing-price-value -->';
         // Optionally add currency symbol
         if ($currency == true) {
             $listing_price_symbol .= '<span class="listing-price-symbol">' . wpsight_get_currency() . '</span><!-- .listing-price-symbol -->';
         }
     } else {
         // Optionally add currency symbol
         if ($currency == true) {
             $listing_price_symbol = '<span class="listing-price-symbol">' . wpsight_get_currency() . '</span><!-- .listing-price-symbol -->';
         }
         $listing_price_symbol .= '<span class="listing-price-value">' . $listing_price . '</span><!-- .listing-price-value -->';
     }
     // endif $currency_symbol
     // Merge price with markup and currency
     $listing_price = $listing_price_symbol;
     // Add period if listing is for rent and period is set
     if ($show_period == true) {
         $rental_period = get_post_meta($post_id, '_price_period', true);
         if ($listing_status == 'rent' && !empty($rental_period)) {
             $listing_price = $listing_price . ' <span class="listing-rental-period">/ ' . wpsight_get_rental_period($rental_period) . '</span><!-- .listing-rental-period -->';
         }
     }
     // endif $show_period
     // Return price value
     return apply_filters('wpsight_listing_price_value', $listing_price);
 }