WordPress 主题在构造函数中使用了一个类,其中配置了钩子add_action,remove_action
。
类中的这些钩子配置如下:
add_action( 'woocommerce_before_main_content', array( $this, 'wrapper_start' ), 10 );
add_action( 'woocommerce_after_main_content', array( $this, 'wrapper_end' ), 10 );
add_filter('single_product_archive_thumbnail_size', array( $this, 'modify_product_thumbnail_size') );
我正在尝试像这样重新定义:
function theme_change_actions() {
remove_action('woocommerce_single_product_summary', array( 'Theme_WooCommerce', 'add_next_prev_product_to_single' ), 4);
}
add_action( 'init', 'theme_change_actions' );
但没有任何效果。Theme_WooCommerce
是相关类的名称。
有没有办法在子主题中覆盖这些钩子?
您正在连接一个类方法并断开一个静态方法。常规方法在对象上,而静态方法在类上。
要删除附加到对象的钩子,请从此处使用此函数https://gist.github.com/tripflex/c6518efc1753cf2392559866b4bd1a53
例子: