Last active
March 28, 2024 12:07
-
-
Save wpmudev-sls/49002fe954e9006b36dfee817689dac2 to your computer and use it in GitHub Desktop.
[Forminator Pro] - Autofill default address in the adress field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: [Forminator Pro] Autofill default address | |
* Description: Autofills default address selected in the default location setting. | |
* Author: Prashant @ WPMUDEV | |
* Task: SLS-5955 | |
* Author URI: https://premium.wpmudev.org | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; // Exit if accessed directly. | |
} | |
function wpmudev_autofill_default_address_field() { | |
global $post; | |
if ( is_a( $post, 'WP_Post' ) && ! has_shortcode( $post->post_content, 'forminator_form' ) ) { | |
return; | |
} | |
?> | |
<script type='text/javascript'> | |
jQuery(document).ready(function($) { | |
setTimeout(function() { | |
$('.forminator-custom-form').trigger('after.load.forminator'); | |
}, 100); | |
$(document).on('after.load.forminator', function(e, form_id) { | |
if ( e.target.id == 'forminator-module-894' ) { // Please change the form ID. | |
$('input[name="address-1-street_address"]').val('Test Street'); | |
$('input[name="address-1-city"]').val('Test City'); | |
$('input[name="address-1-state"]').val('Test State'); | |
$('input[name="address-1-zip"]').val('123456'); | |
$('select[name="address-1-country"]').val('India').trigger('change'); | |
$(document).on('forminator:set_current_location', function(){ | |
$('input[name="address-1-street_address"]').val(''); | |
$('input[name="address-1-city"]').val(''); | |
$('input[name="address-1-state"]').val(''); | |
$('input[name="address-1-zip"]').val(''); | |
$('select[name="address-1-country"]').val('').trigger('change'); | |
}); | |
} | |
}); | |
}); | |
</script> | |
<?php | |
} | |
add_action( 'wp_footer', 'wpmudev_autofill_default_address_field', 9999 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment