-
-
Save lukecav/ada74c86180e3caaf51b67e7f957db4d to your computer and use it in GitHub Desktop.
Disable PayPal for WooCommerce plugin on all pages other than cart and checkout
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
<?php | |
/* | |
Plugin Name: Disable PayPal for WooCommerce Plugin | |
Plugin URI: https://github.com/lukecav | |
Description: Disable PayPal for WooCommerce plugin on all pages other than cart and checkout. | |
Author: Luke Cavanagh | |
Version: 1.0.0 | |
*/ | |
add_filter( 'option_active_plugins', 'disable_plugins_per_page' ); | |
function disable_plugins_per_page( $plugin_list ) { | |
// Quit immediately if in admin area. | |
if ( is_admin() ) { | |
return $plugin_list; | |
} | |
$disable_plugins = array ( | |
// Plugin Name => Urls *not* to disable on. | |
'paypal-for-woocommerce/paypal-for-woocommerce.php' => array( '/cart/', '/checkout/' ), | |
); | |
$plugins_to_disable = array(); | |
foreach ( $plugin_list as $plugin ) { | |
if (true == array_key_exists( $plugin, $disable_plugins ) ) { | |
//error_log( "Found $plugin in list of active plugins." ); | |
if ( false === array_search( $_SERVER['REQUEST_URI'], $disable_plugins[ $plugin ] ) ) { | |
//error_log( "Disable $plugin on ".$_SERVER['REQUEST_URI']."." ); | |
$plugins_to_disable[] = $plugin; | |
} | |
} | |
} | |
// If there are plugins to disable then remove them from the list, | |
// otherwise return the original list. | |
if ( count( $plugins_to_disable ) ) { | |
$new_list = array_diff( $plugin_list, $plugins_to_disable ); | |
return $new_list; | |
} | |
else { | |
return $plugin_list; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment