Set default country for booking form
- <?php
- add_action( 'wp_footer', function () {
- ?>
- <script>
- (function () {
- const country = 'US'; // Change to your country code: US, GB, AU, DE, etc.
- function setCountry() {
- document.querySelectorAll(
- 'select#dbem_country, ' +
- 'select[id*="dbem_country"], ' +
- 'select[name*="dbem_country"]'
- ).forEach(function (field) {
- if (field.value !== '') {
- field.value = country;
- field.querySelector('option[value="' + country + '"]')?.setAttribute('selected', 'selected');
- if (window.jQuery) {
- window.jQuery(field).val(country).trigger('change');
- } else {
- field.dispatchEvent(new Event('change', { bubbles: true }));
- }
- }
- });
- }
- document.addEventListener('DOMContentLoaded', setCountry);
- window.addEventListener('load', setCountry);
- new MutationObserver(setCountry).observe(document.documentElement, {
- childList: true,
- subtree: true
- });
- })();
- </script>
- <?php
- }, 999 );
Pasted 2026-08-20 16:11:20
Short link:
Short link:
Recent Public Pastes