211
правок
8j0rn (обсуждение | вклад) Нет описания правки |
8j0rn (обсуждение | вклад) Нет описания правки Метка: визуальный редактор отключён |
||
| Строка 247: | Строка 247: | ||
} | } | ||
add_filter( 'epl_price_rent_period', '_8j0rn_translate_rent_period' ); | add_filter( 'epl_price_rent_period', '_8j0rn_translate_rent_period' ); | ||
</syntaxhighlight> | |||
=== 2.11. Исправляем адреса в карточках объектов=== | |||
====2.11.1. Функция для форматирования адреса==== | |||
<syntaxhighlight lang="php"> | |||
// Кастомная функция для форматирования адреса | |||
function _8i0rn_get_formatted_property_address($street, $street_separator = true, $separator_symbol = ',') { | |||
// Получаем объект текущего свойства | |||
global $property; | |||
/* | |||
// Проверяем, что $property является объектом и имеет метод get_property_meta | |||
if (!is_object($property) || !method_exists($property, 'get_property_meta')) { | |||
return $street; // Возвращаем оригинальный адрес, если объект не корректен | |||
} | |||
*/ | |||
$_8i0rn_street = ''; | |||
// Добавляем название улицы | |||
$street_name = $property->get_property_meta( 'property_address_street' ); | |||
if ( ! empty( $street_name ) ) { | |||
$_8i0rn_street .= $street_name; | |||
} | |||
// Добавляем номер дома | |||
$street_number = $property->get_property_meta( 'property_address_street_number' ); | |||
if ( ! empty( $street_number ) ) { | |||
$_8i0rn_street .= ' дом ' . $street_number; | |||
} | |||
//Добавляем саб-номер дома | |||
$sub_number = $property->get_property_meta( 'property_address_sub_number' ); | |||
if ( ! empty( $sub_number ) ) { | |||
$_8i0rn_street .= ' кв. ' . $sub_number . ' '; | |||
} | |||
// Добавляем номер квартиры | |||
$lot_number = $property->get_property_meta( 'property_address_lot_number' ); | |||
if ( ! empty( $lot_number ) ) { | |||
$_8i0rn_street .= 'лот № ' . $lot_number . ' '; | |||
if ( true === $street_separator ) { | |||
$separator_symbol = apply_filters( 'epl_property_address_separator', $separator_symbol ); | |||
$_8i0rn_street .= $separator_symbol; | |||
} | |||
} | |||
return $_8i0rn_street; | |||
} | |||
// Подключаем кастомную функцию через фильтр | |||
add_filter('epl_get_formatted_property_address', '_8i0rn_get_formatted_property_address', 10, 1); | |||
</syntaxhighlight> | |||
====2.11.2. Новая функция формирования адресов==== | |||
<syntaxhighlight lang="php"> | |||
// Новая функция формирования адресов | |||
function _8j0rn_epl_property_the_address( $full = true, $street_separator = true, $separator_symbol = ',' ) { | |||
global $property, $epl_settings; | |||
if ( ! is_bool( $full ) ) { | |||
$full = true; | |||
} | |||
$epl_property_address_separator = apply_filters( 'epl_property_address_separator', ',' ); // Улица и дом | |||
$epl_property_address_separator_suburb = apply_filters( 'epl_property_address_separator_suburb', false ); // | |||
$epl_property_address_separator_city = apply_filters( 'epl_property_address_separator_city', false ); | |||
?> | |||
<?php | |||
$text_link = ''; | |||
if ( true === $full ) { | |||
?> | |||
<span class="entry-title-sub"> | |||
<span class="item-pcode"><?php | |||
// Выводим индекс | |||
echo esc_attr( $property->get_property_meta( 'property_address_postal_code' ) ); | |||
$text_link .= esc_attr( $property->get_property_meta( 'property_address_postal_code' ) ) ?></span> | |||
<?php | |||
// Выводим страну (если настройки того требуют) | |||
if ( 'yes' === $property->get_epl_settings( 'epl_enable_country_field' ) ) { | |||
?> | |||
<span class="item-country"><?php | |||
echo esc_attr( $property->get_property_meta( 'property_address_country' ) ); | |||
$text_link .= ' ' . esc_attr( $property->get_property_meta( 'property_address_country' ) ); ?></span> | |||
<?php | |||
} | |||
?> | |||
<span class="item-state"><?php | |||
// Выводим область | |||
echo esc_attr( $property->get_property_meta( 'property_address_state' ) ); | |||
$text_link .= ' ' . esc_attr( $property->get_property_meta( 'property_address_state' ) ); ?></span> | |||
<?php | |||
if ( 'yes' === $property->get_epl_settings( 'epl_enable_city_field' ) ) { | |||
?> | |||
<span class="item-city"><?php | |||
// Выводим город | |||
echo esc_attr( $property->get_property_meta( 'property_address_city' ) ); | |||
$text_link .= ' ' . esc_attr( $property->get_property_meta( 'property_address_city' ) ); ?></span> | |||
<?php | |||
if ( true === $epl_property_address_separator_city && strlen( trim( $property->get_property_meta( 'property_address_city' ) ) ) ) { | |||
echo '<span class="item-separator">' . esc_attr( $epl_property_address_separator ) . '</span>'; | |||
$text_link .= ' ' . esc_attr( $epl_property_address_separator ); | |||
} | |||
} | |||
?> | |||
<?php | |||
// Определяем категорию объекта Коммерческая/Бизнес или Аренда/Продажа (Коммерческая/Бизнес не обновлял за ненадобностью) | |||
if ( 'commercial' === $property->post_type || 'business' === $property->post_type ) { | |||
if ( 'yes' === $property->get_property_meta( 'property_com_display_suburb' ) || 'yes' === $property->get_property_meta( 'property_address_display' ) ) { | |||
?> | |||
<span class="item-suburb">(Коммерческие-Бизнес требует настройки)<?php echo esc_attr( $property->get_property_meta( 'property_address_suburb' ) ); | |||
$text_link .= ' ' . esc_attr( $property->get_property_meta( 'property_address_suburb' ) ); ?></span> | |||
<?php | |||
if ( true === $epl_property_address_separator_suburb && strlen( trim( $property->get_property_meta( 'property_address_suburb' ) ) ) ) { | |||
echo '<span class="item-separator">' . esc_attr( $epl_property_address_separator ) . '</span>'; | |||
$text_link .= ' ' . esc_attr( $epl_property_address_separator ); | |||
} | |||
} | |||
} else { | |||
?> | |||
<span class="item-suburb"><?php | |||
// выводим город-область-индекс (нужно исправить на индекс-область-город) | |||
echo esc_attr( $property->get_property_meta( 'property_address_suburb' ) ); | |||
$text_link .= ' ' . esc_attr( $property->get_property_meta( 'property_address_suburb' ) ); ?></span> | |||
<?php | |||
if ( true === $epl_property_address_separator_suburb && strlen( trim( $property->get_property_meta( 'property_address_suburb' ) ) ) ) { | |||
echo '<span class="item-separator">' . esc_attr( $epl_property_address_separator ) . '</span>'; | |||
$text_link .= ' ' . esc_attr( $epl_property_address_separator ); | |||
} | |||
} | |||
?> | |||
</span> | |||
<?php // выводим дом и улицу (нужно исправить на улица-дом) | |||
if ( 'yes' === $property->get_property_meta( 'property_address_display' ) ) { ?> | |||
<span class="item-street"><?php | |||
echo wp_kses_post( $property->get_formatted_property_address( $street_separator, $separator_symbol ) ); | |||
$text_link .= ' ' . wp_kses_post( $property->get_formatted_property_address( $street_separator, $separator_symbol ) ); ?></span> | |||
<?php } ?> | |||
<?php | |||
} | |||
echo '<a href="#">' . $text_link . '</a>'; | |||
} | |||
// Отключаем старые экшены | |||
function remove_epl_default_actions() { | |||
remove_action('epl_property_title', 'epl_property_the_address', 10); | |||
remove_action('epl_property_tab_address', 'epl_property_the_address', 10); | |||
remove_action('epl_property_address', 'epl_property_the_address', 10); | |||
} | |||
add_action('init', 'remove_epl_default_actions'); | |||
</syntaxhighlight> | |||
====2.11.3. Заключительные настройки исправления адресов карточек==== | |||
<syntaxhighlight lang="php"> | |||
// Подключаем новые экшены | |||
function add_custom_epl_actions() { | |||
add_action('epl_property_title', '_8j0rn_epl_property_the_address', 10, 3); | |||
add_action('epl_property_tab_address', '_8j0rn_epl_property_the_address', 10, 3); | |||
add_action('epl_property_address', '_8j0rn_epl_property_the_address', 10, 3); | |||
} | |||
add_action('init', 'add_custom_epl_actions'); | |||
</syntaxhighlight> | </syntaxhighlight> | ||