1

I'm trying to remove a Wordpress action that's been declared by Woocommerce Subscriptions in the following way:

class WC_Subscriptions_Synchroniser {

  public static function init() {

    add_action( 'woocommerce_single_product_summary', __CLASS__ . '::products_first_payment_date', 31 );
  }

  add_action( 'init', 'WC_Subscriptions_Synchroniser::init' );

}

The codex has a couple of examples for remove actions that have been declared within a class: https://codex.wordpress.org/Function_Reference/remove_action

Which I've adapted & combined in the following way without success:

$my_class = new WC_Subscriptions_Synchroniser;
function remove_my_class_action(){

  global $my_class;
  remove_action( 'woocommerce_single_product_summary', array( $my_class, 'products_first_payment_date' ), 40 );
  remove_action( 'woocommerce_single_product_summary', array( 'WC_Subscriptions_Synchroniser', 'products_first_payment_date' ), 40 );

}
add_action( 'woocommerce_single_product_summary', 'remove_my_class_action', 40 );

I've also tried hooking the remove_my_class_action action with init but that doesn't work either.

Help please!

4

1 回答 1

2

Two things... First, the products_first_payment_date() method is static, so you don't need to instantiate a class object in order to remove it. And second, a function needs to be removed before it is run. Therefore, I think an earlier priority on your add_action() should do the trick.

function remove_my_class_action(){
  remove_action( 'woocommerce_single_product_summary', array( 'WC_Subscriptions_Synchroniser', 'products_first_payment_date' ), 40 );
}
add_action( 'woocommerce_single_product_summary', 'remove_my_class_action', 10 );
于 2017-04-13T19:13:01.587 回答