Nik
Nik

Reputation: 671

Disable public function in WooCommerce plugin

I am using the Woocommerce Admin Custom Order Fields plugin which is causing issues when searching orders in the backend. When I run a slow query on the admin order search function it searches through these custom fields and adds 10secs or so to the search.

I have found the function that does it with the plugin and I'm trying to work out the best way to disable the custom fields being included in the search.

When I comment out this code the search is quick, a couple of seconds. I want to add an override or disable it somehow in my functions.php

public function add_search_fields( $search_fields ) {

    foreach ( wc_admin_custom_order_fields()->get_order_fields() as $order_field ) {

        if ( 'date' === $order_field->type  ) {
            array_push( $search_fields, $order_field->get_meta_key() . '_formatted' );
        } else {
            array_push( $search_fields, $order_field->get_meta_key() );
        }
    }

    return $search_fields;
}

Can anyone give me some pointers on how to stop this executing without editing the plugin files directly? Cheers Nik

Upvotes: 0

Views: 267

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 254383

Don't comment all the function code, but just the active code inside the function, like:

public function add_search_fields( $search_fields ) {
    /* 
    foreach ( wc_admin_custom_order_fields()->get_order_fields() as $order_field ) {

        /* if ( 'date' === $order_field->type  ) {
            array_push( $search_fields, $order_field->get_meta_key() . '_formatted' );
        } else {
            array_push( $search_fields, $order_field->get_meta_key() );
        }
    }
    */  
    return $search_fields;
}

Now this function will not have any effect, as it's active code is commented.

Now overwriting any core plugin code is really something to avoid… There are always different ways to change things, like using available hooks and other things may be more complicated…

Upvotes: 1

Related Questions