Advertisement:

Author Topic: Price dropdown based on category  (Read 354 times)

Rudy

  • Newbie
  • *
  • Posts: 1
Price dropdown based on category
« on: January 08, 2019, 12:30:38 pm »
Hi, i'm new to osclass and need some help.
I created a price min and max dropdown with options.
What i try now is to show all of this option when no category selected,
and hide some of this options when you select a category.

How to do this?

Code: [Select]
if(isset($sCategory)) {
      $category = array("pk_i_id" => $sCategory);
} else {
    if(osc_is_home_page() && osc_is_search_page()){
      $category = 'null';
    } else {$category = array("pk_i_id" => '0');}
}
  osc_categories_select('sCategory', $category , __('All property types', 'ctg_housing')) ; ?>

Here my example of my price min option

Code: [Select]
    <div class="search-box-price-min columns-3">
      <select  id="priceMin" name="sPriceMin" >
        <option value="" hidden >Price Min</option>
        <option value="1" <?php if(osc_search_price_min() == 1) echo 'selected' ?>>From Any</option>
        <option value="5000" <?php if(osc_search_price_min() == 5000) echo 'selected' ?>>₱ 5,000</option>
        <option value="10000" <?php if(osc_search_price_min() == 10000) echo 'selected' ?>>₱ 10,000</option>
<option value="15000" <?php if(osc_search_price_min() == 15000) echo 'selected' ?>>₱ 15,000</option>
        <option value="20000" <?php if(osc_search_price_min() == 20000) echo 'selected' ?>>₱ 100,000</option>
<option value="25000" <?php if(osc_search_price_min() == 25000) echo 'selected' ?>>₱ 250,000</option>
<option value="30000" <?php if(osc_search_price_min() == 30000) echo 'selected' ?>>₱ 500,000</option>
      </select>
    </div>

When selected category for rent only this shows

Code: [Select]
    <div class="search-box-price-min columns-3">
      <select  id="priceMin" name="sPriceMin" >
        <option value="" hidden >Price Min</option>
        <option value="1" <?php if(osc_search_price_min() == 1) echo 'selected' ?>>From Any</option>
        <option value="5000" <?php if(osc_search_price_min() == 5000) echo 'selected' ?>>₱ 5,000</option>
        <option value="10000" <?php if(osc_search_price_min() == 10000) echo 'selected' ?>>₱ 10,000</option>
<option value="15000" <?php if(osc_search_price_min() == 15000) echo 'selected' ?>>₱ 15,000</option>
    </div>

When selected category for sale only this shows

Code: [Select]
    <div class="search-box-price-min columns-3">
      <select  id="priceMin" name="sPriceMin" >
        <option value="" hidden >Price Min</option>
        <option value="1" <?php if(osc_search_price_min() == 1) echo 'selected' ?>>From Any</option>
        <option value="20000" <?php if(osc_search_price_min() == 20000) echo 'selected' ?>>₱ 100,000</option>
<option value="25000" <?php if(osc_search_price_min() == 25000) echo 'selected' ?>>₱ 250,000</option>
<option value="30000" <?php if(osc_search_price_min() == 30000) echo 'selected' ?>>₱ 500,000</option>
      </select>
    </div>

Hope someone can help me, thanks

WEBmods

  • Hero Member
  • *****
  • Posts: 937
  • github.com/webmods-croatia/love-osclass/ | patrick
Re: Price dropdown based on category
« Reply #1 on: January 11, 2019, 01:30:29 am »
Hello,

You can get the current search category with "osc_search_category_id()" function and then compare it to your list of categories and finally according fields.

Code: [Select]
<?php
$for_sale_categories 
= array('ID of category 1''ID of category 2''ID of category 3'); // put all your for sale category id's here in quotes separated with commas.
$for_rent_categories = array('ID of category 1''ID of category 2''ID of category 3'); // put all your for rent category id's here in quotes separated with commas.
$search_category osc_search_category_id()[0];

if(
in_array($search_category$for_sale_categories)) { ?>

    <!--- Show for sale price select, for sale category selected. --->
    <div class="search-box-price-min columns-3">
      <select  id="priceMin" name="sPriceMin" >
        <option value="" hidden >Price Min</option>
        <option value="1" <?php if(osc_search_price_min() == 1) echo 'selected' ?>>From Any</option>
        <option value="20000" <?php if(osc_search_price_min() == 20000) echo 'selected' ?>>₱ 100,000</option>
<option value="25000" <?php if(osc_search_price_min() == 25000) echo 'selected' ?>>₱ 250,000</option>
<option value="30000" <?php if(osc_search_price_min() == 30000) echo 'selected' ?>>₱ 500,000</option>
      </select>
    </div>
<?php } elseif(in_array($search_category$for_rent_categories)) { ?>
    <!--- Show for rent price select, for rent category selected. --->
    <div class="search-box-price-min columns-3">
      <select  id="priceMin" name="sPriceMin" >
        <option value="" hidden >Price Min</option>
        <option value="1" <?php if(osc_search_price_min() == 1) echo 'selected' ?>>From Any</option>
        <option value="5000" <?php if(osc_search_price_min() == 5000) echo 'selected' ?>>₱ 5,000</option>
        <option value="10000" <?php if(osc_search_price_min() == 10000) echo 'selected' ?>>₱ 10,000</option>
<option value="15000" <?php if(osc_search_price_min() == 15000) echo 'selected' ?>>₱ 15,000</option>
      </select>
    </div>
<?php } else { ?>
    <!--- Show default price select, no for sale or for rent category selected. --->
    <div class="search-box-price-min columns-3">
      <select  id="priceMin" name="sPriceMin" >
        <option value="" hidden >Price Min</option>
        <option value="1" <?php if(osc_search_price_min() == 1) echo 'selected' ?>>From Any</option>
        <option value="5000" <?php if(osc_search_price_min() == 5000) echo 'selected' ?>>₱ 5,000</option>
        <option value="10000" <?php if(osc_search_price_min() == 10000) echo 'selected' ?>>₱ 10,000</option>
<option value="15000" <?php if(osc_search_price_min() == 15000) echo 'selected' ?>>₱ 15,000</option>
        <option value="20000" <?php if(osc_search_price_min() == 20000) echo 'selected' ?>>₱ 100,000</option>
<option value="25000" <?php if(osc_search_price_min() == 25000) echo 'selected' ?>>₱ 250,000</option>
        <option value="30000" <?php if(osc_search_price_min() == 30000) echo 'selected' ?>>₱ 500,000</option>
      </select>
    </div>
<?php }
?>


I haven't tested, but should work. Make sure to keep a backup of the files you edit. :)

Regards.