Skip to content

7. Helpers

Falko Joseph edited this page Mar 4, 2021 · 7 revisions

1. Introduction

These methods are available on a property's single template page. (single-estate.php).

2. Project helpers

Min/max living area [project page only]

If you want to show the minimum and maximum living area of a project with multiple units. This will return the smallest living area of all of its units, and the largest living area of all of its units.

// $iso = e.g. en_GB, fr_FR, ...
WP_SweepBright_Query::min_max_living_area($iso);

Example request:

WP_SweepBright_Query::min_max_living_area('nl_BE');

Example response:

[
  'min' => '50m²',
  'max' => '250m²'
]

Min/max plot area [project page only]

If you want to show the minimum and maximum plot area of a project with multiple units. This will return the smallest plot area of all of its units, and the largest plot area of all of its units.

// $iso = e.g. en_GB, fr_FR, ...
WP_SweepBright_Query::min_max_plot_area($iso);

Example request:

WP_SweepBright_Query::min_max_plot_area('nl_BE');

Example response:

[
  'min' => '50m²',
  'max' => '250m²'
]

Min/max price [project page only]

If you want to show the minimum and maximum price of a project with multiple units. This will return the lowest price of all of its units, and the highest price of all of its units.

// $iso = e.g. en_GB, fr_FR, ...
WP_SweepBright_Query::min_max_price($iso = false, $project_id = false);

Example request:

WP_SweepBright_Query::min_max_price('nl_BE', false);

Example response:

[
  'min' => '150,000',
  'max' => '200,000'
]

3. Formatting

Format unit

If you want to show the minimum and maximum price of a project with multiple units. This will return the lowest price of all of its units, and the highest price of all of its units.

// $unit = e.g. sq_ft, sq_m, are, acre, ...
WP_SweepBright_Query::format_unit($unit);

Example request:

WP_SweepBright_Query::format_unit(get_field('sizes')['liveable_area']['unit']);

Example response:

// If the unit is set to e.g. sq_m in SweepBright

Format number

Method to format numbers based on an ISO code.

// $iso = e.g. en_GB, fr_FR, ...
WP_SweepBright_Query::format_number($number, $iso);

Example request:

WP_SweepBright_Query::format_number(get_field('price')['amount'], 'en_GB');

Example response:

// If the price is set to e.g. 350000 in SweepBright
350,000

Get the price

Method to format the price with its currency included.

// $iso = e.g. en_GB, fr_FR, ...
WP_SweepBright_Query::get_the_price($iso);

Example request:

WP_SweepBright_Query::get_the_price('en_GB');

Example response:

// If the price is set to e.g. 350000 in SweepBright
£350,000

Get the WordPress post ID from a property

Useful when you need to perform a WordPress specific task.

// $id = SweepBright ID of a property e.g. '000-000-000', ...
WP_SweepBright_Helpers::get_post_ID_from_estate($id);

Example request:

WP_SweepBright_Helpers::get_post_ID_from_estate('000-000-000');

Example response:

// Example post ID
35
Clone this wiki locally