Created
June 13, 2018 13:06
-
-
Save ideadude/5e87ff108a131ba163c306d615da87cd to your computer and use it in GitHub Desktop.
Replace the default payment information HTML for the Stripe class in Paid Memberships Pro
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
/** | |
* Replace the default payment information HTML for the Stripe class. | |
* Add this code into a custom plugin. | |
* Note that you will need to monitor PMPro updates in case your custom code conflicts with new version of PMPro. | |
*/ | |
// Disable the defaults and load our own functions. | |
function my_stripe_checkout_html() { | |
//disable the defaults | |
remove_filter('pmpro_include_payment_information_fields', array('PMProGateway_stripe', 'pmpro_include_payment_information_fields')); | |
//add my methods | |
add_filter('pmpro_include_payment_information_fields', 'my_pmpro_include_payment_information_fields'); | |
} | |
add_action( 'init', 'my_stripe_checkout_html', 11 ); // using priority 11 to make sure this runs after the PMPro Stripe class runs | |
// Change this function below as needed. | |
function my_pmpro_include_payment_information_fields($include) | |
{ | |
//global vars | |
global $pmpro_requirebilling, $pmpro_show_discount_code, $discount_code, $CardType, $AccountNumber, $ExpirationMonth, $ExpirationYear; | |
//get accepted credit cards | |
$pmpro_accepted_credit_cards = pmpro_getOption("accepted_credit_cards"); | |
$pmpro_accepted_credit_cards = explode(",", $pmpro_accepted_credit_cards); | |
$pmpro_accepted_credit_cards_string = pmpro_implodeToEnglish($pmpro_accepted_credit_cards); | |
//include ours | |
?> | |
<div id="pmpro_payment_information_fields" class="pmpro_checkout" <?php if(!$pmpro_requirebilling || apply_filters("pmpro_hide_payment_information_fields", false) ) { ?>style="display: none;"<?php } ?>> | |
<h3> | |
<span class="pmpro_checkout-h3-name"><?php _e('Payment Information', 'paid-memberships-pro' );?></span> | |
<span class="pmpro_checkout-h3-msg"><?php printf(__('We Accept %s', 'paid-memberships-pro' ), $pmpro_accepted_credit_cards_string);?></span> | |
</h3> | |
<?php $sslseal = pmpro_getOption("sslseal"); ?> | |
<?php if(!empty($sslseal)) { ?> | |
<div class="pmpro_checkout-fields-display-seal"> | |
<?php } ?> | |
<div class="pmpro_checkout-fields<?php if(!empty($sslseal)) { ?> pmpro_checkout-fields-leftcol<?php } ?>"> | |
<?php | |
$pmpro_include_cardtype_field = apply_filters('pmpro_include_cardtype_field', false); | |
if($pmpro_include_cardtype_field) { ?> | |
<div class="pmpro_checkout-field pmpro_payment-card-type"> | |
<label for="CardType"><?php _e('Card Type', 'paid-memberships-pro' );?></label> | |
<select id="CardType" class=" <?php echo pmpro_getClassForField("CardType");?>"> | |
<?php foreach($pmpro_accepted_credit_cards as $cc) { ?> | |
<option value="<?php echo $cc?>" <?php if($CardType == $cc) { ?>selected="selected"<?php } ?>><?php echo $cc?></option> | |
<?php } ?> | |
</select> | |
</div> | |
<?php } else { ?> | |
<input type="hidden" id="CardType" name="CardType" value="<?php echo esc_attr($CardType);?>" /> | |
<script> | |
<!-- | |
jQuery(document).ready(function() { | |
jQuery('#AccountNumber').validateCreditCard(function(result) { | |
var cardtypenames = { | |
"amex":"American Express", | |
"diners_club_carte_blanche":"Diners Club Carte Blanche", | |
"diners_club_international":"Diners Club International", | |
"discover":"Discover", | |
"jcb":"JCB", | |
"laser":"Laser", | |
"maestro":"Maestro", | |
"mastercard":"Mastercard", | |
"visa":"Visa", | |
"visa_electron":"Visa Electron" | |
} | |
if(result.card_type) | |
jQuery('#CardType').val(cardtypenames[result.card_type.name]); | |
else | |
jQuery('#CardType').val('Unknown Card Type'); | |
}); | |
}); | |
--> | |
</script> | |
<?php } ?> | |
<div class="pmpro_checkout-field pmpro_payment-account-number"> | |
<label for="AccountNumber"><?php _e('Card Number', 'paid-memberships-pro' );?></label> | |
<input id="AccountNumber" class="input <?php echo pmpro_getClassForField("AccountNumber");?>" type="text" size="25" value="<?php echo esc_attr($AccountNumber)?>" autocomplete="off" /> | |
</div> | |
<div class="pmpro_checkout-field pmpro_payment-expiration"> | |
<label for="ExpirationMonth"><?php _e('Expiration Date', 'paid-memberships-pro' );?></label> | |
<select id="ExpirationMonth" class=" <?php echo pmpro_getClassForField("ExpirationMonth");?>"> | |
<option value="01" <?php if($ExpirationMonth == "01") { ?>selected="selected"<?php } ?>>01</option> | |
<option value="02" <?php if($ExpirationMonth == "02") { ?>selected="selected"<?php } ?>>02</option> | |
<option value="03" <?php if($ExpirationMonth == "03") { ?>selected="selected"<?php } ?>>03</option> | |
<option value="04" <?php if($ExpirationMonth == "04") { ?>selected="selected"<?php } ?>>04</option> | |
<option value="05" <?php if($ExpirationMonth == "05") { ?>selected="selected"<?php } ?>>05</option> | |
<option value="06" <?php if($ExpirationMonth == "06") { ?>selected="selected"<?php } ?>>06</option> | |
<option value="07" <?php if($ExpirationMonth == "07") { ?>selected="selected"<?php } ?>>07</option> | |
<option value="08" <?php if($ExpirationMonth == "08") { ?>selected="selected"<?php } ?>>08</option> | |
<option value="09" <?php if($ExpirationMonth == "09") { ?>selected="selected"<?php } ?>>09</option> | |
<option value="10" <?php if($ExpirationMonth == "10") { ?>selected="selected"<?php } ?>>10</option> | |
<option value="11" <?php if($ExpirationMonth == "11") { ?>selected="selected"<?php } ?>>11</option> | |
<option value="12" <?php if($ExpirationMonth == "12") { ?>selected="selected"<?php } ?>>12</option> | |
</select>/<select id="ExpirationYear" class=" <?php echo pmpro_getClassForField("ExpirationYear");?>"> | |
<?php | |
for($i = date_i18n("Y"); $i < date_i18n("Y") + 10; $i++) { ?> | |
<option value="<?php echo $i?>" <?php if($ExpirationYear == $i) { ?>selected="selected"<?php } ?>><?php echo $i?></option> | |
<?php } ?> | |
</select> | |
</div> | |
<?php | |
$pmpro_show_cvv = apply_filters("pmpro_show_cvv", true); | |
if($pmpro_show_cvv) { ?> | |
<div class="pmpro_checkout-field pmpro_payment-cvv"> | |
<label for="CVV"><?php _e('Security Code (CVC)', 'paid-memberships-pro' );?></label> | |
<input id="CVV" type="text" size="4" value="<?php if(!empty($_REQUEST['CVV'])) { echo esc_attr(sanitize_text_field($_REQUEST['CVV'])); }?>" class="input <?php echo pmpro_getClassForField("CVV");?>" /> <small>(<a href="javascript:void(0);" onclick="javascript:window.open('<?php echo pmpro_https_filter(PMPRO_URL)?>/pages/popup-cvv.html','cvv','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=600, height=475');"><?php _e("what's this?", 'paid-memberships-pro' );?></a>)</small> | |
</div> | |
<?php } ?> | |
<?php if($pmpro_show_discount_code) { ?> | |
<div class="pmpro_checkout-field pmpro_payment-discount-code"> | |
<label for="discount_code"><?php _e('Discount Code', 'paid-memberships-pro' );?></label> | |
<input class="input <?php echo pmpro_getClassForField("discount_code");?>" id="discount_code" name="discount_code" type="text" size="10" value="<?php echo esc_attr($discount_code)?>" /> | |
<input type="button" id="discount_code_button" name="discount_code_button" value="<?php _e('Apply', 'paid-memberships-pro' );?>" /> | |
<p id="discount_code_message" class="pmpro_message" style="display: none;"></p> | |
</div> | |
<?php } ?> | |
</div> <!-- end pmpro_checkout-fields --> | |
<?php if(!empty($sslseal)) { ?> | |
<div class="pmpro_checkout-fields-rightcol pmpro_sslseal"><?php echo stripslashes($sslseal); ?></div> | |
</div> <!-- end pmpro_checkout-fields-display-seal --> | |
<?php } ?> | |
</div> <!-- end pmpro_payment_information_fields --> | |
<?php | |
//don't include the default | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment