-
-
Save MindyPostoff/c70dc98a099a9bf1c2f0 to your computer and use it in GitHub Desktop.
/** | |
* A function to reorder the default display of fields on the WooCommerce Bookings form | |
* Put this function in your theme's functions.php file | |
*/ | |
function custom_order_booking_fields ( $fields ) { | |
$reorder = array(); | |
$reorder[] = $fields['wc_bookings_field_duration']; // Duration | |
$reorder[] = $fields['wc_bookings_field_resource']; // Resource | |
$reorder[] = $fields['wc_bookings_field_persons']; // Persons | |
$reorder[] = $fields['wc_bookings_field_start_date']; // Calendar or Start Date | |
return $reorder; | |
} | |
add_filter( 'booking_form_fields', 'custom_order_booking_fields'); |
Thanks!
but if you site has custom person types the positions is quite different, so we did this:
$reorder = array();
$reorder[] = $fields['wc_bookings_field_start_date']; // Calendar or Start Date
$reorder[] = $fields['wc_bookings_field_duration']; // Duration
$reorder[] = $fields['wc_bookings_field_resource']; // Resource
foreach(array_keys($fields) as $field){
if(strpos($field, 'wc_bookings_field_persons') === 0){ //handle with $fields['wc_bookings_field_persons_XXXX'] fields
$reorder[] = $fields[$field]; // insert any person field
}
}
return $reorder;
@Bocapio thank you, that is very helpful.
Do you know how we can add plus and minus buttons to the person type fields? I added buttons to the number.php file and also added a function but it not working right; here is my code: https://gist.github.com/TomasHurtz/2acb6a4142faeafd390a749df764eb02
This has been incredibly helpful, thank you so much!
Very off topic but I'm curious if you'd have any insight on this - I have a person type to add a maximum of one additional person to the booking and since the number doesn't need to vary I'd like to just change it from a text/number field to a checkbox, do you have any ideas on how I might be able to accomplish that?
@lp-ben you could try to change the template file 'number.php' and modify the html to show checkbox with something like this?
<input type="checkbox" value="1" id="custom" checked="checked" /><span>One selected</span>
I'm not sure how this would affect all products that use person types? Try and see if it works.
@TomasHurtz I tried that and it looked correct but gave an error saying "The minimum persons per group is 1" even when it was checked.
@webstersgr I believe you could do that in the template file ? I need to add + - buttons for numbers field - did you manage that? If so, kindly share :-)
@Ayzoh1 I also need to do this. Did you find a solution?
[_wc_booking_has_person_types] => Array
(
[0] => 1
)
But how can we check the array in $reorder[] = $fields['wc_bookings_field_persons']; // Persons
["_persons"]=> array(1) { [0]=> int(1) }
I know in jquery we could use
But I don't know how to add this into the function above.