WP Residence Help WP Residence Help

  • WpEstate
  • How to Build Your Website
  • Video Tutorials
  • Client Support
  • API
Home / Technical how to | Custom Code Required, WpResidence 5.0 / WPEstate Beds and Baths Component

WPEstate Beds and Baths Component

427 views 0

The wpestate_show_beds_baths_component function, along with its associated JavaScript function wpestate_beds_baths_component, forms a crucial part of the WPEstate theme. These functions are responsible for generating and managing the beds and baths selection component in property search forms. This guide will explain how these functions work, how to extend them, and how to customize their appearance.

PHP Function Overview

Here’s the basic structure of the PHP function:


function wpestate_show_beds_baths_component($appendix, $placeholder, $elementor_label, $term_counter_elementor, $position, $active='') {
// Function body
}

Parameters:

  • $appendix: Determines if the component should be half-width
  • $placeholder: Custom placeholder text for the dropdown
  • $elementor_label: Label for Elementor (not used in the function)
  • $term_counter_elementor: Counter for Elementor terms (not used in the function)
  • $position: Position of the component (not used in the function)
  • $active: Whether the component is in an active state

JavaScript Function Overview

The wpestate_beds_baths_component JavaScript function manages the interactive behavior of the component. Here’s a breakdown of its main parts:

1. handleItemClick Function

This function handles the selection of bed or bath items:


function handleItemClick(itemClass, inputClass) {
var selected_item = jQuery(this);
var parent = selected_item.parent();
var component = selected_item.closest('.wpestate-beds-baths-popoup-component');
parent.find(itemClass).removeClass('wp_estate_component_item_selected');
selected_item.addClass('wp_estate_component_item_selected');
var selected_value = selected_item.attr('data-value');
jQuery(inputClass).val(selected_value);
update_label(component);
}

2. update_label Function

This function updates the dropdown label based on the selected values:


function update_label(component){
var selected_beds = component.find('.wp_estate_beds_component_item.wp_estate_component_item_selected').length > 0 ? component.find('.wp_estate_beds_component_item.wp_estate_component_item_selected').attr('data-value') : '0';
var selected_baths = component.find('.wp_estate_baths_component_item.wp_estate_component_item_selected').length > 0 ? component.find('.wp_estate_baths_component_item.wp_estate_component_item_selected').attr('data-value') : '0';
var update_label = parseFloat(selected_beds) + '+ ' + control_vars.bd + '/' + parseFloat(selected_baths) + '+ ' + control_vars.ba;
component.find('.dropdown-toggle').text(update_label);
}

3. Event Handlers

The function sets up several event handlers:

  • Click handlers for bed and bath selection items
  • A reset handler to clear selections
  • A ‘done’ handler to complete the selection process

Interactions Between PHP and JavaScript

The PHP function generates the HTML structure, while the JavaScript function manages the interactive behavior. Key points of interaction include:

  • The PHP function creates elements with specific classes (e.g., wp_estate_beds_component_item) that the JavaScript function uses to attach event listeners.
  • The JavaScript function updates hidden input fields (.wpresidence-componentsbeds and .wpresidence-componentsbaths) that were created by the PHP function.
  • The reset functionality in JavaScript relies on the data-default-value attribute set by the PHP function.

Extending the Functions

Extending the PHP Function

To extend the wpestate_show_beds_baths_component function, you can use WordPress filters or create a child theme and override the function. Here’s an example of how to add a new option to the beds selection:


function add_extra_bed_option($beds_selection) {
$extra_option = '<div class="wp_estate_beds_component_item" data-value="5+">5+</div>';
return $beds_selection . $extra_option;
}
add_filter('wpestate_beds_selection', 'add_extra_bed_option');

Extending the JavaScript Function

To extend the JavaScript functionality, you can add your own functions or modify the existing ones. For example, to add a custom action after selection:


jQuery(document).ready(function($) {
var originalFunction = wpestate_beds_baths_component;
wpestate_beds_baths_component = function() {
originalFunction();
$('.wpestate-beds-baths-popoup-done').on('click', function() {
// Your custom action here
console.log('Selection completed!');
});
};
});

CSS Classes and Customization

The main CSS classes used in this component are:

  • wpestate-beds-baths-popoup-component: Main container class
  • wpestate-multiselect-custom-style: Style for the dropdown button
  • wpestate-beds-baths-popoup-wrapper: Wrapper for the dropdown content
  • wp_estate_beds_component_item: Individual bed option item
  • wp_estate_baths_component_item: Individual bath option item
  • wpestate-beds-baths-popoup-reset: Reset button
  • wpestate-beds-baths-popoup-done: Done button

To customize the appearance, you can add custom CSS to your theme or use the WordPress Customizer. Here’s an example of how to change the background color of the dropdown:


.wpestate-beds-baths-popoup-component .dropdown-menu {
background-color: #f0f0f0;
}

Conclusion

The combination of the PHP function wpestate_show_beds_baths_component and the JavaScript function wpestate_beds_baths_component creates a versatile and interactive beds and baths selection component in the WPEstate theme. By understanding their structure and interaction, and using WordPress hooks, custom JavaScript, and CSS, you can customize and extend their functionality to meet your specific needs.

Technical how to | Custom Code RequiredWpResidence 5.0

Related Articles

  • Technical – How to Change the Minimum Image Dimensions for Property Uploads in WPResidence
  • Introduction to WPResidence Header Customization
  • Understanding WPResidence Header Types: An Overview
  • Customizing the WPResidence Logo Display

WP Residence Documentation

  • 1. General
    • How to Get Support
    • Get your buyer license code.
    • Use SSL / https
    • Server / Theme Requirements
  • 2. Installation
  • 3. Installation FAQ
  • 4. Advanced Search
    • Advanced Search Display Settings
    • Advanced Search Form
    • Geolocation Search for Half Map
    • Save Search Theme Options
    • Advanced Search Colors
  • 5. Agent, Agency & Developers
  • 6. Property Page
  • 7. Properties List
  • 8. Property Taxonomies
  • WpResidence Elementor Studio
  • 10. Blog Posts & Blog List
  • 11. Shortcodes
    • Contact Form
    • Featured Agency/Developer
    • Membership Packages
    • Testimonials
    • Google Map with Property Marker
    • Listings per Agent, Agency or Developer
    • Display Categories
    • Agent List
    • Recent Items Slider
    • Recent items
    • List Properties or Articles by ID
    • Featured Agent
    • Featured Article
    • Featured Property
    • Login & Register Form
    • Icon Content Box Shortcode
  • 12. Widgets
  • Theme Options
    • General Settings
    • User Types Settings
    • Appearance
    • Logos & Favicon
    • Header
    • Footer Style and Colors
    • Price & Currency
    • Property Custom Fields
    • Features & Amenities
    • Listing Labels
    • Theme Slider
    • Permalinks
    • Splash Page
    • Social & Contact
    • Map Settings
    • Pin Management
    • How read from file works
    • General Design Settings
    • Custom Colors Settings
    • Header Design & Colors
    • Mobile Menu Colors
    • User Dashboard Colors
    • Print PDF Design
    • Property, Agent, Blog Lists Design Settings
    • Sidebar Widget Design
    • Font management
    • How to add custom CSS
    • Custom Property Card Unit – Beta version
    • Email Management
    • Import & Export theme options
    • reCaptcha settings
    • YELP API Integration
    • iHomefinder Optima Express IDX
    • MEMBERSHIP & PAYMENT Settings
    • Property Submission Page
    • PayPal Setup
    • Stripe Setup
    • Wire Transfer Payment Method
  • Translation
  • FAQ
  • Pages
  • Header
  • Footer
  • Google or Open Street Maps
  • Payment Options
  • Plugins
    • Included Plugins
    • Third Party Plugins – IDX Compatibility
    • Third Party Plugins – Multi Languages
    • Third party Plugins – Other
  • Technical
    • Technical how to | Custom Code Required
    • Technical: Child Theme

Join Us On

Powered by WP Estate - All Rights Reserved
  • WpEstate
  • How to Build Your Website
  • Video Tutorials
  • Client Support
  • API