I want to modify a function in a plugin. It is declared in the plugin’s main file like this:

class WCPGSK_Main {
  ...
  public function wcpgsk_email_after_order_table($order) {
    ...
  }
}

Add called from there like this:

add_action( 'woocommerce_email_after_order_table', array($this, 'wcpgsk_email_after_order_table') );

I guess it would be possible to replace it if had an access to the class in functions.php. Then I would be able to write something like this:

$wcpgsk = new WCPGSK_Main;

remove_action( 'woocommerce_email_after_order_table', array($wcpgsk, 'wcpgsk_email_after_order_table') );

function customized_wcpgsk_email_after_order_table($order) {
  ...
}
add_action( 'woocommerce_email_after_order_table', array($wcpgsk, 'customized_wcpgsk_email_after_order_table') );

My thought to get an access to the class in the functions.php file was to include the file where the class is declared in functions.php:

require_once('/wp-content/plugins/woocommerce-poor-guys-swiss-knife/woocommerce-poor-guys-swiss-knife.php');
$wcpgsk = new WCPGSK_Main;
...

But this does not work because the plugin’s file is included when the plugin is getting initialized in WordPress, I guess.

Is there a way to rewrite the function without touching plugin’s files?

3 s
3

This should work:

add_action( 'woocommerce_init', 'remove_wcpgsk_email_order_table' );
function remove_wcpgsk_email_order_table() {

    global $wcpgsk;
    remove_action( 'woocommerce_email_after_order_table', array( $wcpgsk, 'wcpgsk_email_after_order_table' ) );

}

Leave a Reply

Your email address will not be published. Required fields are marked *