• Resolved trevgreguk

    (@trevgreguk)


    Hi, Getting a little frustrated with something that seemed simple enough.
    I have created the additional field as shown in the documentation and it appears on the booking page,

    Once the form is submitted, there is no value in the database.
    I have also asked AI to check the code, with the following response.
    “The custom field not appearing in the database, even though it is visible on the booking form, indicates that the Hotelier plugin is not successfully processing or saving the data. The problem is not with your code, which correctly defines and adds the field to the form, but with how the plugin handles the submitted data.”

    Can you help, please.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author benitolopez

    (@benitolopez)

    Hello,

    Please share your complete code. Use pastebin or similar and paste the URL.

    Thread Starter trevgreguk

    (@trevgreguk)

    Hi, thanks for the prompt reply πŸ™‚

    This is the code: https://pastebin.com/u6ZqWPux

    This is the booking form, the additional field Recommended by can be seen.
    But once the booking form is submitted, there is no corresponding field or value in the database that can be used.

    • This reply was modified 1 month, 2 weeks ago by trevgreguk.
    Plugin Author benitolopez

    (@benitolopez)

    The code seems correct. Where did you search the value in the DB?

    Did you try the recommended way to retrieve it?

    $your_field = $reservation->guest_zswcustom_field;
    Thread Starter trevgreguk

    (@trevgreguk)

    I used phpmyadmin and looked at the wp _postmeta everytime i tested by completing a booking.

    The only field missing is the additional.

    Plugin Author benitolopez

    (@benitolopez)

    Ok, the code works automatically if you use the “hotelier_booking_default_address_fields” filter. To update the reservation meta when you use the “hotelier_booking_additional_information_fields” filter, you can use this code:

    function hotelier_custom_update_reservation_meta( $reservation_id, $form_data ) {
    if ( isset( $form_data['zswcustom_field'] ) ) {
    update_post_meta( $reservation_id, 'zswcustom_field', $form_data['zswcustom_field'] );
    }
    }
    add_action( 'hotelier_booking_update_reservation_meta', 'hotelier_custom_update_reservation_meta', 10, 2 );
    Thread Starter trevgreguk

    (@trevgreguk)

    Thank you πŸ™‚
    I can now see zswcustom_field with a value in the database,
    but the code to display the value in the admin reservation screen also does not display the custom field and it does not use the guest_ as stated in your documentations.

    Can you please advise the correct code I should now use to display the custom field on the Admin Reservation Screen.
    This is the code I tried to use.

    // Display the "Recommended by" custom field in the admin reservation details
    function custom_fields_in_reservation_data() {
    global $post;
    $reservation = htl_get_reservation( $post->ID );
    if ( $reservation->zswcustom_field ) {
    $field = array(
    'id' => 'zswcustom_field',
    'label' => esc_html__( 'Recommended by', 'text-domain' ),
    'value' => $reservation->zswcustom_field,
    );
    HTL_Meta_Boxes_Helper::text_input( $field );
    }
    }
    add_action( 'hotelier_reservation_after_guest_special_requests', 'custom_fields_in_reservation_data' );

    function add_custom_field_to_reservation_metaboxes( $metaboxes ) {
    $metaboxes['zswcustom_field'] = 'text';
    return $metaboxes;
    }
    add_filter( 'hotelier_reservation_meta_boxes', 'add_custom_field_to_reservation_metaboxes' );
    Plugin Author benitolopez

    (@benitolopez)

    This is the correct code:

    // Display the "Recommended by" custom field in the admin reservation details
    function custom_fields_in_reservation_data() {
    global $post;
    $custom_field = get_post_meta( $post->ID, 'zswcustom_field', true );
    if ( $custom_field ) {
    $field = array(
    'id' => 'zswcustom_field',
    'label' => esc_html__( 'Recommended by', 'text-domain' ),
    'value' => $custom_field,
    );
    HTL_Meta_Boxes_Helper::text_input( $field );
    }
    }
    add_action( 'hotelier_reservation_after_guest_special_requests', 'custom_fields_in_reservation_data' );
    add_action( 'hotelier_reservation_after_guest_special_requets', 'custom_fields_in_reservation_data' );
    Thread Starter trevgreguk

    (@trevgreguk)

    Hi Benito,
    I have tried the code and there is no change.
    The custom fields still not in the Admin Reservation πŸ™

    Plugin Author benitolopez

    (@benitolopez)

    I’m using the exact same code and it works:
    https://lopezb.d.pr/i/1gmQf0

    Did you copy the exact same code I sent above? Note that there are two:

    add_action( 'hotelier_reservation_after_guest_special_requests', 'custom_fields_in_reservation_data' );
    add_action( 'hotelier_reservation_after_guest_special_requets', 'custom_fields_in_reservation_data' );

    Thread Starter trevgreguk

    (@trevgreguk)

    Oh Wow… sorry i presumed the last line was a duplicate paste and it had an ‘s’ missing from _requests.

    I have now added the exact line and It now works… Thank you so much

    Plugin Author benitolopez

    (@benitolopez)

    Yes, the current action has a typo, “requets”. I will fix it in the next update. That’s why my code has two lines, because the new action will be “hotelier_reservation_after_guest_special_requests”. So you will be ready.

Viewing 11 replies - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.