Created
November 6, 2020 22:29
-
-
Save ronalfy/c53e4126647c5d03c3ee17430ad3059a to your computer and use it in GitHub Desktop.
PMPro - Set Maximum Character Count Checkout Field
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
<?php | |
/** | |
* Forces maxinput on input fields on the checkout page. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_checkout_page_min_number() { | |
// Ensure we're on the checkout page. | |
if ( ! is_page( get_option( 'pmpro_checkout_page_id' ) ) ) { | |
return; | |
} | |
// Output jQuery to output the new table column and data. | |
if ( wp_script_is( 'jquery', 'done' ) ) { | |
?> | |
<script> | |
// Need to change the var to the input you'd like to target via jQuery. | |
var $input = jQuery( 'input[type=text]' ); | |
// Change the length needed. | |
$input.prop('maxlength','10'); | |
</script> | |
<?php | |
} | |
?> | |
<?php | |
} | |
add_action( 'wp_footer', 'my_pmpro_checkout_page_min_number' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment