wordpresswoocommercewoocommerce-bookings

How do I add new fields to the booking form in the WooCommerce Bookings extension for admin users only?


I am using WooCommerce and the official WooCommerce Bookings extension. I want to add a custom price override field to the booking form, which is the one generated by the WC_Booking_form class. This new fields should only be visible to users creating a booking from the backend (Bookings > Add Booking etc). I then have a working filter function which should take this value and recalculates the AJAX price using woocommerce_bookings_calculated_booking_cost.

I've tried adding to the $fields variable available with the booking_form_fields filter, but I only seem to be able to modify existing fields and not add new fields here.

As a test, I seem to be able to achieve what I want by using the add_field method within the WC_Booking_form class, but obviously I need to be able to make this modification from outside the plugin.

Any help much appreciated. Thanks


Solution

  • The booking form can be updated by adding to the $fields array using the booking_form_fields. However, the issue I had was that the field must be one of those supported by the templates in woocommerce-bookings/templates/booking-form.

    This means that if you want to create a textarea field on the booking form, you first need to create a textarea booking form field template. These templates can be created in the usual way (in your theme) for the frontend, however I've yet to find out how to create them to for the admin screen....