0

I have a business website for vacation home rentals in which the WordPress theme has its own booking system for house bookings only and it has been great!

I also, have Tour/Services (not Houses) also bookable but for these I use WooCommerce/WooCommerce Bookings plugins, not the House booking system.

Everything has been great!

But recently the theme update introduced a WooCommerce checkout option for the Home booking system which never existed prior to the update. Although I have the themes WooCommerce checkout option turned OFF, the code is still being executed in the theme's core plugin. I have been going back and forth with an open support ticket with the theme provider for a few weeks for them to put a conditional statement to NOT run the new code when the user has the option turned OFF but I do not know when or if it will ever be done. What happens now is that the theme's core plugin is manipulating the WooCommerce checkout and after the final step of placing the order of any Tour/Services in which I had always been previously using WooCommerce separately now times out after placing the order and generates over 1,000 additional "Phantom" Checkout pages in the back-end.

Bottom line: When 3 lines (lines 27-29) are commented out of the theme's core plugin file, everything works fine. But I do not want to have to comment out these 3 lines after each plugin update.

//add_action( 'woocommerce_thankyou', array($this,'order_attach') );

//add_filter( 'woocommerce_checkout_fields', array($this,'custom_override_checkout_fields') );

//add_filter('woocommerce_create_account_default_checked', '__return_true');

Here is the full code (with lines 27-29 commented out): https://pastebin.com/jqtBpCpA

I have tried the instructions on both pages below without success: https://mekshq.com/remove-wordpress-action-filter-class https://github.com/herewithme/wp-filters-extras

I have inserted the following into the functions.php file

METHOD 1:

global $Wpestate_Global_Payments; //get access to the class object instance

remove_action( 'woocommerce_thankyou', array($Wpestate_Global_Payments,'order_attach') );
remove_filter( 'woocommerce_checkout_fields', array($Wpestate_Global_Payments,'custom_override_checkout_fields') ); 
remove_filter('woocommerce_create_account_default_checked', '__return_true');

Then using the plugin, here: https://github.com/herewithme/wp-filters-extras I tried both methods:

METHOD 2:

remove_filters_with_method_name( 'woocommerce_thankyou', 'order_attach' );
remove_filters_with_method_name( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
remove_filters_with_method_name( 'woocommerce_create_account_default_checked', '__return_true' );

METHOD 3:

remove_filters_for_anonymous_class( 'woocommerce_thankyou', 'Wpestate_Global_Payments', 'order_attach' );
remove_filters_for_anonymous_class( 'woocommerce_checkout_fields', 'Wpestate_Global_Payments', 'custom_override_checkout_fields' );
remove_filters_for_anonymous_class( 'woocommerce_create_account_default_checked', 'Wpestate_Global_Payments', '__return_true' );

FROM THE PLUGIN FILE:

class Wpestate_Global_Payments {

    public $stripe_payments;
    public $is_woo;  
    public $userID;
    public $user_email;

    function __construct() {

        $this->is_woo   =   wprentals_get_option('wp_estate_enable_woo','') ;
        $current_user   =   wp_get_current_user();

        $this->userID                  =    $current_user->ID;
        $this->user_email              =    $current_user->user_email;
        add_filter( 'woocommerce_cart_item_permalink','__return_false');
        add_action( 'wp_ajax_wpestate_woo_pay',                 array( $this, 'wpestate_woo_pay') );
        add_action( 'wp_ajax_mopriv_wpestate_woo_pay',          array( $this, 'wpestate_woo_pay') );
        add_filter( 'woocommerce_thankyou_order_received_text', array($this, 'wpestate_woocommerce_thankyou_order_received_text'),10,2 );
        add_action( 'woocommerce_before_single_product',        array($this, 'wpestate_product_redirect') );
        add_action( 'woocommerce_product_query',                array($this, 'wpestate_custom_pre_get_posts_query' ));  
        add_action( 'woocommerce_order_status_completed',       array($this, 'wpestate_payment_complete') );
        add_action( 'woocommerce_order_status_processing',      array($this, 'wpestate_payment_complete') );       
       //EVERYTHING WORKS ONLY WHEN THE 3 LINES BELOW ARE COMMENTED OUT 
       //add_action( 'woocommerce_thankyou', array($this,'order_attach') );
       //add_filter( 'woocommerce_checkout_fields', array($this,'custom_override_checkout_fields') );
       //add_filter('woocommerce_create_account_default_checked', '__return_true');

Can anyone provide any insight into how I can insert a remove_action & remove_filter for each in the functions.php to remove/unhook the 3 actions/filters that I currently have commented out in the plugin file?

  • the method 1 looks like the most efficient but you must be sur to run this code after filters are added in Wpestate_Global_Payments and not before. then you have to trace the call of this object to know when it's instanciated. – Kaperto Nov 10 at 22:40
0

You unhook things the way you added them.

In this case, you need to pass a callable that matches what was added. Normally this is the function name e.g. 'my_function', but for an non-static method in an object, it has to be [ $object, 'method_name' ] where $object is a reference to the object.

How you get that reference though is a murkier subject. Some plugins use singletons, and have instance methods that will get you the object. Some plugins put new ClassName(); at the end of the file creating anonymous objects, making it nearly impossible to get the object reference for most developers. Some use global variables, etc.

Refer to the documentation for the plugin you're working with, ask their developer support, and remember, 3rd party plugins are offtopic on WP Stack Exchange.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.