Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Created November 22, 2014 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save strangerstudios/dad8feba2fafa9fd4241 to your computer and use it in GitHub Desktop.
Save strangerstudios/dad8feba2fafa9fd4241 to your computer and use it in GitHub Desktop.
Get PMPro Pay By Check and PMPro Add PayPal Express to work together.
/*
Get PMPro Pay By Check and PMPro Add PayPal Express to work together.
*/
//remove the checkout_boxes code from both plugins
function my_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", "my_pmpro_checkout_boxes_payment_options");
}
add_action('init', 'my_init_pmpro_payment_options');
//new combined checkout options
function my_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> &nbsp;
<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> &nbsp;
<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> &nbsp;
</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');?> &raquo;" 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