Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eighty20results/41d3108fb92e573c5cbbdf3114e7cf29 to your computer and use it in GitHub Desktop.
Save eighty20results/41d3108fb92e573c5cbbdf3114e7cf29 to your computer and use it in GitHub Desktop.
Removes the "Pay with PayPal Express" choice from the checkout page when the user uses one of the specified Membership Level IDs
<?php
/*
Plugin Name: PMPro Customizations: Remove PayPal Express as payment option for Membership Level
Plugin URI: https://eighty20results.com/paid-memberships-pro/do-it-for-me/
Description: Removes PayPal Express as a payment option on the PMPro Checkout page when the user has selected a specific membership level.
Version: 1.0
Author: Eighty / 20 Results by Wicked Strong Chicks, LLC <thomas@eighty20results.com>
Author URI: https://eighty20results.com/thomas-sjolshagen/
License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
License: GPLv2 or later
* Copyright (c) 2018 - Eighty / 20 Results by Wicked Strong Chicks.
* ALL RIGHTS RESERVED
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Remove the PayPal Express or Credit Card payment option from the PMPro checkout page
* when selecting a membership level with the specified $level_to_exclude_paypal_from (integer)
*/
function remove_paypalexpress_from_use_for_level() {
global $pmpro_pages;
/**
* @param int[] $level_to_exclude_paypal_from - A comma separated list of Membership Level IDs where
* you want to remove PayPal Express as an payment option
* for Paid Memberships Pro
* (When the 'Add PayPal Express Option at Checkout' add-on
* is installed)
*/
$level_to_exclude_paypal_from = array( 1, );
if ( !isset( $pmpro_pages['checkout'] ) || is_page( $pmpro_pages['checkout'] ) ) {
return;
}
$level_id = isset( $_REQUEST['level'] ) ? intval( $_REQUEST['level'] ) : null;
if ( empty( $level_id ) || $level_to_exclude_paypal_from !== $level_id ) {
return;
}
if ( ! function_exists( 'is_plugin_inactive' ) ) {
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
}
if ( is_plugin_inactive( 'pmpro-add-paypal-express/pmpro-add-paypal-express.php' ) ) {
return;
}
remove_action( 'pmpro_checkout_boxes', 'pmproappe_pmpro_checkout_boxes', 20 );
}
add_action('init', 'remove_paypalexpress_from_use_for_level', 99 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment