Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Hide PayPal button if user is not approved to check out for this level.
<?php
/**
* Hide PayPal button if user is not approved to check out for this level.
*
* 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_before_submit_button_hide_ppe( $restricted ) {
global $pmpro_level, $current_user;
if ( ! class_exists( 'PMPro_Approvals' ) ) {
return;
}
$approvals = PMPro_Approvals::get_instance();
//does this level require approval of another level?
$restrict_checkout = $approvals::restrictCheckout( $pmpro_level->id );
if ( $restrict_checkout ) {
$other_level = pmpro_getLevel( $restrict_checkout );
//check that they are approved and not denied for that other level
if ( $approvals::isDenied( null, $pmpro_level->id ) || $approvals::isDenied( null, $restrict_checkout ) || $approvals::isPending( null, $restrict_checkout ) ) {
?>
<style>
#pmpro_btn-submit-paypalexpress {
display: none;
}
</style>
<?php
}
}
}
add_filter( 'pmpro_checkout_before_submit_button', 'my_pmpro_checkout_before_submit_button_hide_ppe', 100 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment