删除并覆盖WooCommerce流程注册操作

时间:2014-06-01 14:31:33

标签: php wordpress woocommerce

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

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

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/

我真的很感激任何帮助!

1 个答案:

答案 0 :(得分:1)

两种选择,考虑到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隐藏其钩子的evil anonymous object,以便您可以:

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