functions.php
<?php
/**
* Remove Class Filter Without Access to Class Object
*
* In order to use the core WordPress remove_filter() on a filter added with the callback
* to a class, you either have to have access to that class object, or it has to be a call
* to a static method. This method allows you to remove filters with a class callback
* without having access to the object.
*
* @param string $tag Filter to remove
* @param string $class_name Class name for the filter's callback
* @param string $method_name Method name for the filter's callback
* @param int $priority Priority of the filter (default 10)
*
* @return bool
*/
function remove_class_filter( $tag, $class_name = '', $method_name = '', $priority = 10 ){
global $wp_filter;
// Check for filter and specific priority (default 10)
if( ! isset( $wp_filter[ $tag ][ $priority ] ) || ! is_array( $wp_filter[ $tag ][ $priority ] ) ) return FALSE;
// Check each filter with specified priority
foreach( (array) $wp_filter[ $tag ][ $priority ] as $filter_id => $filter ) {
// Filter should always be an array - array( $this, 'method' ), if not goto next
if( ! isset( $filter['function'] ) || ! is_array( $filter['function'] ) ) continue;
// If first value in array is not an object, it can't be a class
if( ! is_object( $filter['function'][0] ) ) continue;
// If class name does not match the class we're looking for, goto next
if( get_class( $filter['function'][0] ) !== $class_name ) continue;
// Yay we found our filter
if( $filter['function'][1] === $method_name ) {
// Now let's remove it from the array
unset( $wp_filter[ $tag ][ $priority ][ $filter_id ] );
// and if it was the only filter in that priority, unset that priority
if( empty($wp_filter[ $tag ][ $priority ]) ) unset($wp_filter[ $tag ][ $priority ]);
// and if the only filter for that tag, set the tag to an empty array
if( empty($wp_filter[ $tag ]) ) $wp_filter[ $tag ] = array();
// Remove this filter from merged_filters (specifies if filters have been sorted)
unset($GLOBALS['merged_filters'][ $tag ]);
return TRUE;
}
}
return FALSE;
}
/**
* Now we remove the filter/action so it doesn't show on the cart page
*/
remove_class_filter( 'woocommerce_proceed_to_checkout', 'WC_Gateway_PPEC_Cart_Handler', 'display_paypal_button', 20 );
No comments yet.