Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save daltonrooney/a2e555d73defc400ee91 to your computer and use it in GitHub Desktop.
Save daltonrooney/a2e555d73defc400ee91 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: WooCommerce Disable PayPal for Subscriptions
* Plugin URI: https://gist.github.com/thenbrent/6641526
* Description: Want to disable PayPal for subscription purchases, but still offer it as an option for buying one-off products? Activate this plugin.
* Author: Brent Shepherd
* Author URI: http://find.brentshepherd.com/
* Version: 1.0
*
* 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/>.
*
* @author Brent Shepherd
* @since 1.0
*/
function wcsdp_get_available_payment_gateways( $available_gateways ) {
if ( class_exists( 'WC_Subscriptions_Cart' ) && ( WC_Subscriptions_Cart::cart_contains_subscription() || ( isset( $_GET['order_id'] ) && WC_Subscriptions_Order::order_contains_subscription( $_GET['order_id'] ) ) ) ) {
if ( isset( $available_gateways['paypal'] ) ) {
unset( $available_gateways['paypal'] );
}
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'wcsdp_get_available_payment_gateways', 11 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment