| |
| <?php
|
| function mepr_remove_state_field() {
|
| global $post;
|
| $mepr_options = MeprOptions::fetch();
|
| $is_product_page = ( false !== ( $prd = MeprProduct::is_product_page($post) ) );
|
|
|
| if( $mepr_options->global_styles || $is_product_page ) {
|
| ?>
|
| <script>
|
| mepr_populate_states = function( obj ) { ( function( $ ) {
|
| var country = obj.val();
|
| var form = obj.closest( '.mepr-form' );
|
|
|
| if( form == undefined ) { return; }
|
|
|
|
|
| form.find( '.mepr-states-dropdown option' ).remove();
|
|
|
| var statesDropdown = form.find( '.mepr-states-dropdown' );
|
| var statesText = form.find( '.mepr-states-text' );
|
|
|
|
|
| if ( statesDropdown.length <= 0 || statesText.length <= 0 ) { return; }
|
|
|
|
|
| var fieldname = statesDropdown.data( 'fieldname' );
|
| var value = statesDropdown.data( 'value' ).toString();
|
|
|
| if( fieldname == undefined || value == undefined ) { return; }
|
|
|
|
|
| fieldname = fieldname.replace( /^\s+/,'' );
|
| fieldname = fieldname.replace( /\s+$/,'' );
|
| value = value.replace( /^\s+/,'' );
|
| value = value.replace( /\s+$/,'' );
|
|
|
| var required = !!obj.attr( 'required' );
|
|
|
| if ( MeprI18n.states[country] !== undefined ) {
|
| $( '.mepr_mepr-address-state' ).show();
|
|
|
| statesDropdown.attr( 'name', fieldname );
|
| statesDropdown.show();
|
| statesText.removeAttr( 'name' );
|
| statesText.hide();
|
| if (required) {
|
| statesText.removeAttr( 'required' );
|
| statesDropdown.attr( 'required','' );
|
| }
|
|
|
| statesDropdown.append( '<option value="">' + MeprI18n.please_select_state + '</option>' );
|
|
|
| for ( var st in MeprI18n.states[country] ) {
|
| var selected = ( value===st ? ' selected="selected"' : '' );
|
| statesDropdown.append( '<option value="' + st + '" ' + selected + '>' + MeprI18n.states[country][st] + '</option>' );
|
| }
|
| } else {
|
| statesDropdown.removeAttr( 'name' );
|
| statesDropdown.hide();
|
|
|
| statesText.attr( 'name', fieldname );
|
| statesText.val( '(none)' );
|
| $( '.mepr_mepr-address-state' ).hide();
|
|
|
| if ( required ) {
|
| statesDropdown.removeAttr( 'required' );
|
| statesText.removeAttr( 'required' );
|
| }
|
| }
|
| })( jQuery )};
|
| </script>
|
| <?php
|
| }
|
| }
|
|
|
| add_action( 'wp_footer', 'mepr_remove_state_field' );
|
| |
| |
Comments