删除和覆盖WooCommerce过程注册操作


Remove and Override WooCommerce Process Registration action

我正在开发一个插件来定制woocommerce注册,并试图避免直接编辑核心文件。

我需要通过我的插件在woocommerce的includes/class-wc-form-handler.php文件中覆盖或替换process_registration动作。

add_action( 'init', array( $this, 'process_registration' ) );

我试着跟随链接,但他们没有工作。此外,这些页面上提到的文件在woocommerce当前版本中不存在。我也检查了woocommerce文档,但似乎他们没有钩子。

http://wordpress.org/support/topic/overriding-woocommerce_process_registration-in-child-theme-functionsphp

Woocommerce挂钩:http://docs.woothemes.com/document/hooks/

我真的很感激任何帮助!

考虑到WC方法的开始,有两个选项:

class WC_Form_Handler
    public function __construct() {
        add_action( 'init', array( $this, 'process_registration' ) );
    }
    public function process_registration() {
        if ( ! empty( $_POST['register'] ) ) {
            wp_verify_nonce( $_POST['register'], 'woocommerce-register' );
            # etc
        }
    }
}
new WC_Form_Handler();
  1. 添加一个优先级最高的init钩子,然后重复unset($_POST['register'])。WC没有指定优先级,所以它在10上运行,这是默认的。

    add_action( 'init', function() { /* dup, unset, do your thing */ }, 1 ); // priority 1
    
  2. 追踪Woo隐藏钩子的邪恶匿名对象,以便您可以:

    // pseudo code, go to WPSE for the real thing
    remove_hook( 'init', 'woo_process_registration' );