/*
Theme Name:  Listeo ChildTheme
Theme URI: http://listeo.pro
Author: Purethemes
Author URI: http://themeforest.net/user/purethemes
Description: Directory WordPress Theme by Purethemes
Version: 1.0
License: ThemeForest
License URI: http://themeforest.net/licenses
Text Domain: listeo
Domain Path: /languages/
Tags: light, responsive-layout, post-formats, theme-options, translation-ready, two-columns
Template:  listeo
*/

ajouter_filtre( 'submit_listing_form_fields', 'listeo_child_force_children_field', 25, 2 );
fonction listeo_child_force_children_field( $sections, $listing_type ) {
    si ( 'location' !== $listing_type ) {
        renvoyer $sections;
    }

    si ( vide( $sections['basic_prices'] ) || ! est_tableau( $sections['basic_prices'] ) ) {
        renvoyer $sections;
    }

    si ( vide( $sections['basic_prices']['fields'] ) || ! is_array( $sections['basic_prices']['fields'] ) ) {
        $sections['basic_prices']['fields'] = tableau();
    }

    si ( isset( $sections['basic_prices']['fields']['_children'] ) ) {
        renvoyer $sections;
    }

    $sections['basic_prices']['fields']['_children'] = tableau(
        'label' => __( 'Enfants autorisés', 'listeo_core' ),
        'type' => 'case à cocher',
        'tooltip' => __( 'Affiche le sélecteur d'enfants dans le widget de réservation pour les annonces de location.', 'listeo_core' ),
        'obligatoire' => faux,
        'placeholder' => '',
        'nom' => '_enfants',
        'classe' => '',
        'priorité' => 10,
        'render_row_col' => '3',
    );

    renvoyer $sections;
}

ajouter_filtre( 'get_post_metadata', 'listeo_child_default_children_meta', 10, 4 );
fonction listeo_child_default_children_meta( $value, $object_id, $meta_key, $single ) {
    si ( '_children' !== $meta_key ) {
        renvoyer $value;
    }

    si (metadata_exists( 'post', $object_id, '_children' ) || ! listeo_child_listing_is_rental( $object_id ) ) {
        renvoyer $value;
    }

    retourner $single ? 'on' : tableau( 'on' );
}

fonction listeo_child_listing_is_rental( $post_id ) {
    si ( 'listing' !== get_post_type( $post_id ) ) {
        renvoyer faux ;
    }

    $listing_type = get_post_meta( $post_id, '_listing_type', true );
    si ( ! vide( $listing_type ) ) {
        renvoyer 'location' === $listing_type;
    }

    $terms = get_the_terms( $post_id, 'listing_type' );
    if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
        pour chaque ( $terms comme $term ) {
            si ( 'location' === $term->slug ) {
                renvoyer vrai ;
            }
        }
    }

    renvoyer faux ;
}