Created
July 16, 2021 15:29
-
-
Save ideadude/bddbf3414942603087c7287f4532ae2e to your computer and use it in GitHub Desktop.
Make the country and state dropdowns select2 fields when using PMPro and the State Dropdowns Add On.
This file contains hidden or 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
/** | |
* Make country and state dropdowns select2 fields. | |
* Requires both the pmpro-state-dropdowns and | |
* pmpro-register-helper plugins to be active. | |
* | |
* Add this to a custom plugin or code snippet. | |
* More info here: https://www.paidmembershipspro.com/how-to-add-code-to-wordpress/ | |
*/ | |
function my_make_country_and_state_select2() { | |
if ( ! is_admin() ) { | |
?> | |
<script> | |
jQuery(document).ready(function(){ | |
jQuery('#bcountry').select2(); | |
jQuery('#bstate').select2(); | |
}); | |
</script> | |
<?php | |
} | |
} | |
add_action( 'wp_footer', 'my_make_country_and_state_select2' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think some versions of the checkout and/or billing page don't have id attributes on the state and country fields. A different bit of JS to add select2 to those fields may be needed if that's the case. You can select2 all of the select fields in the checkout page form using this JS:
jQuery('form.pmpro-form select').select2();