1. Docs
  2. Add Ons
  3. Property Import
  4. Handling Sales and Lettings Availabilities

Handling Sales and Lettings Availabilities

Some formats send different values for availabilities allowing us to distinguish between sales and lettings. This is great and means mapping these when you setup the import is nice and easy.

There are other formats however (BLM for example) that do not differentiate between sales and lettings. For example, they'll send the availability as 'Available'. In this scenario we don't know if this means For Sale or To Let.

To combat this we can map the sales values when setting up the format, but then must use the hooks above to handle the lettings side of things. An example of this for the BLM format, which can be added to your theme's functions.php file, has been included below:

add_action( "propertyhive_property_imported_blm", "correct_property_availability", 10, 2 );
function correct_property_availability($post_id, $property)
{
    if ( $property['TRANS_TYPE_ID'] == '2' )
    {
        // It's a lettings property

        wp_suspend_cache_invalidation( false );
        wp_defer_term_counting( false );
        wp_defer_comment_counting( false );
        
        if ( $property['STATUS_ID'] == '0' ) // AVAILABLE
        {
            wp_delete_object_term_relationships( $post_id, 'availability' );
            wp_set_object_terms( $post_id, 6, 'availability' ); // CHANGE 6 TO BE YOUR 'TO LET' TERM ID
        }
        
        wp_suspend_cache_invalidation( true );
        wp_defer_term_counting( true );
        wp_defer_comment_counting( true );
    }
}

For the Jupix format an example is as follows:

add_action( "propertyhive_property_imported_jupix_xml", "correct_property_availability", 10, 2 );
function correct_property_availability($post_id, $property)
{
    if ( (string)$property->department == 'Lettings' )
    {
        // It's a lettings property

        wp_suspend_cache_invalidation( false );
        wp_defer_term_counting( false );
        wp_defer_comment_counting( false );
        
        if ( (string)$property->availability == '2' ) // To Let
        {
            wp_delete_object_term_relationships( $post_id, 'availability' );
            wp_set_post_terms( $post_id, 6, 'availability' ); // CHANGE 6 TO BE YOUR 'TO LET' TERM ID
        }
        if ( (string)$property->availability == '3' || (string)$property->availability == '4' ) // References Pending / Let Agreed
        {
            wp_delete_object_term_relationships( $post_id, 'availability' );
            wp_set_post_terms( $post_id, 7, 'availability' ); // CHANGE 7 TO BE YOUR 'LET AGREED' TERM ID
        }
        if ( (string)$property->availability == '5' ) // Let
        {
            wp_delete_object_term_relationships( $post_id, 'availability' );
            wp_set_post_terms( $post_id, 8, 'availability' ); // CHANGE 8 TO BE YOUR 'LET' TERM ID
        }
        
        wp_suspend_cache_invalidation( true );
        wp_defer_term_counting( true );
        wp_defer_comment_counting( true );
    }
}

For the Vebra format an example is as follows:

add_action( "propertyhive_property_imported_vebra_api_xml", "correct_property_availability", 10, 2 );
function correct_property_availability($post_id, $property)
{
    $property_attributes = $property->attributes();

    if ( (string)$property_attributes['database'] == '2' || ( (string)$property_attributes['database'] == '5' && (string)$property->commercial->transaction == 'rental' ) )
    {
        // It's a lettings property

        wp_suspend_cache_invalidation( false );
        wp_defer_term_counting( false );
        wp_defer_comment_counting( false );

        if ( (string)$property->web_status == '0' || (string)$property->web_status == '200' ) // To Let - Vebra have two IDs for 'To Let'
        {
            wp_delete_object_term_relationships( $post_id, 'availability' );
            wp_set_post_terms( $post_id, 5, 'availability' ); // CHANGE 5 TO BE YOUR 'TO LET' TERM ID
        }
        if ( (string)$property->web_status == '2' || (string)$property->web_status == '3' || (string)$property->web_status == '4' ) // Under Offer / References Pending / Let Agreed
        {
            wp_delete_object_term_relationships( $post_id, 'availability' );
            wp_set_post_terms( $post_id, 7, 'availability' ); // CHANGE 7 TO BE YOUR 'LET AGREED' TERM ID
        }
        if ( (string)$property->web_status == '1' || (string)$property->web_status == '214' ) // Let - Vebra have two IDs for 'Let'
        {
            wp_delete_object_term_relationships( $post_id, 'availability' );
            wp_set_post_terms( $post_id, 6, 'availability' ); // CHANGE 6 TO BE YOUR 'LET' TERM ID
        }

        wp_suspend_cache_invalidation( true );
        wp_defer_term_counting( true );
        wp_defer_comment_counting( true );
    }
}

For the Domus format an example is as follows:

add_action( "propertyhive_property_imported_domus_xml", "correct_property_availability", 10, 2 );
function correct_property_availability($post_id, $property)
{
    if ( isset($property->sale) &&  (string)$property->sale == 'false' )
    {
        // It's a lettings property

        wp_suspend_cache_invalidation( false );
        wp_defer_term_counting( false );
        wp_defer_comment_counting( false );
        
        if ( (string)$property->status== 'Available' ) // To Let
        {
            wp_delete_object_term_relationships( $post_id, 'availability' );
            wp_set_post_terms( $post_id, 6, 'availability' ); // CHANGE 6 TO BE YOUR 'TO LET' TERM ID
        }
        
        wp_suspend_cache_invalidation( true );
        wp_defer_term_counting( true );
        wp_defer_comment_counting( true );
    }
}
Was this article helpful to you? Yes No