Forked from strangerstudios/my_init_pmpro_payment_options.php
Last active
November 18, 2016 14:30
-
-
Save eighty20results/3919c0377cbbf29172e77c2ce94b1f64 to your computer and use it in GitHub Desktop.
Get PMPro Pay By Check and PMPro Add PayPal Express to work together.
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
/* | |
Plugin Name: Paid Memberships Pro - Pay By Check and PayPal Express at checkout | |
Plugin URI: http://eighty20results.com/paid-memberships-pro/do-it-for-me/ | |
Description: More gracefully handle Pay By Check and PayPal Express as payment options during checkout | |
Version: 1.0 | |
Author: Thomas Sjoslhagen @ Paid Memberships Pro <[email protected]> | |
Author URI: http://eighty20results.com/thomas-sjolshagen | |
*/ | |
/* | |
Get PMPro Pay By Check and PMPro Add PayPal Express to work together. | |
*/ | |
//remove the checkout_boxes code from both plugins | |
function e20r_init_pmpro_payment_options() | |
{ | |
remove_action("pmpro_checkout_boxes", "pmpropbc_checkout_boxes"); | |
remove_action("pmpro_checkout_boxes", "pmproappe_pmpro_checkout_boxes", 20); | |
add_action("pmpro_checkout_boxes", "e20r_pmpro_checkout_boxes_payment_options"); | |
} | |
add_action('init', 'e20r_init_pmpro_payment_options'); | |
//new combined checkout options | |
function e20r_pmpro_checkout_boxes_payment_options() | |
{ | |
//if already using paypal, ignore this | |
$setting_gateway = get_option("pmpro_gateway"); | |
global $pmpro_requirebilling, $gateway, $pmpro_review; | |
//only show this if we're not reviewing | |
if(empty($pmpro_review)) | |
{ | |
?> | |
<table id="pmpro_payment_method" class="pmpro_checkout top1em" width="100%" cellpadding="0" cellspacing="0" border="0" <?php if(!$pmpro_requirebilling) { ?>style="display: none;"<?php } ?>> | |
<thead> | |
<tr> | |
<th><?php _e('Choose your Payment Method', 'pmpro');?></th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td> | |
<div> | |
<input type="radio" name="gateway" value="<?php echo esc_attr($setting_gateway);?>" <?php if(!$gateway || $gateway == $setting_gateway) { ?>checked="checked"<?php } ?> /> | |
<a href="javascript:void(0);" class="pmpro_radio"><?php _e('Check Out with a Credit Card Here', 'pmpro');?></a> | |
<input type="radio" name="gateway" value="paypalexpress" <?php if($gateway == "paypalexpress") { ?>checked="checked"<?php } ?> /> | |
<a href="javascript:void(0);" class="pmpro_radio"><?php _e('Check Out with PayPal', 'pmpro');?></a> | |
<input type="radio" name="gateway" value="check" <?php if($gateway == "check") { ?>checked="checked"<?php } ?> /> | |
<a href="javascript:void(0);" class="pmpro_radio">Pay by Check</a> | |
</div> | |
</td> | |
</tr> | |
</tbody> | |
</table> | |
<?php //here we draw the PayPal Express button, which gets moved in place by JavaScript ?> | |
<span id="pmpro_paypalexpress_checkout" style="display: none;"> | |
<input type="hidden" name="submit-checkout" value="1" /> | |
<input type="image" value="<?php _e('Check Out with PayPal', 'pmpro');?> »" src="<?php echo apply_filters("pmpro_paypal_button_image", "https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif");?>" /> | |
</span> | |
<script> | |
var pmpro_require_billing = <?php if($pmpro_requirebilling) echo "true"; else echo "false";?>; | |
//choosing payment method | |
jQuery(document).ready(function() { | |
//move paypal express button into submit box | |
jQuery('#pmpro_paypalexpress_checkout').appendTo('div.pmpro_submit'); | |
function showPayPalExpressCheckout() | |
{ | |
jQuery('#pmpro_billing_address_fields').hide(); | |
jQuery('#pmpro_payment_information_fields').hide(); | |
jQuery('#pmpro_submit_span').hide(); | |
jQuery('#pmpro_paypalexpress_checkout').show(); | |
pmpro_require_billing = false; | |
} | |
function showCreditCardCheckout() | |
{ | |
jQuery('#pmpro_paypalexpress_checkout').hide(); | |
jQuery('#pmpro_billing_address_fields').show(); | |
jQuery('#pmpro_payment_information_fields').show(); | |
jQuery('#pmpro_submit_span').show(); | |
pmpro_require_billing = true; | |
} | |
function showFreeCheckout() | |
{ | |
jQuery('#pmpro_billing_address_fields').hide(); | |
jQuery('#pmpro_payment_information_fields').hide(); | |
jQuery('#pmpro_submit_span').show(); | |
jQuery('#pmpro_paypalexpress_checkout').hide(); | |
pmpro_require_billing = false; | |
} | |
//detect gateway change | |
jQuery('input[name=gateway]').click(function() { | |
if(jQuery(this).val() == 'paypalexpress') | |
{ | |
showPayPalExpressCheckout(); | |
} | |
else if(jQuery(this).val() == 'check') | |
{ | |
showFreeCheckout(); | |
} | |
else | |
{ | |
showCreditCardCheckout(); | |
} | |
}); | |
//update radio on page load | |
if(jQuery('input[name=gateway]:checked').val() == 'paypalexpress' && pmpro_require_billing == true) | |
{ | |
showPayPalExpressCheckout(); | |
} | |
else if(jQuery('input[name=gateway]:checked').val() == 'check' && pmpro_require_billing == true) | |
{ | |
showFreeCheckout(); | |
} | |
else if(pmpro_require_billing == true) | |
{ | |
showCreditCardCheckout(); | |
} | |
else | |
{ | |
showFreeCheckout(); | |
} | |
//select the radio button if the label is clicked on | |
jQuery('a.pmpro_radio').click(function() { | |
jQuery(this).prev().click(); | |
}); | |
}); | |
</script> | |
<?php | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment