2014-09-03 47 views
0

我想修改函數在Woocommerce wc_create_new_customer,我已經加入這個我functions.php文件...Woocommerce - remove_action不工作

remove_action('init', 'wc_create_new_customer'); 
add_action('init', 'wc_create_new_customer'); 

function wc_create_new_customer($email, $username = '', $password = '') { 
// My custom function 
} 

這顯然給了我一個錯誤wc_create_new_customer有已經被挖空了。我怎樣才能修改這個工作?

回答

1

更改您定製的wc_create_new_customer的名稱(至my_wc_create_new_customer或類似名稱),並在您致電add_action時使用該名稱。

更新:

而不是修改核心功能,你想用一個動作在某個時候某個事件發生時,使自定義函數運行。該woocommerce_created_customer活動由WooCommerce創建一個新的客戶時觸發的,所以你可以連接到該行動,使你的代碼運行:

add_action('woocommerce_created_customer', 'do_things_on_customer_create', 10, 3); 

function do_things_on_customer_create($customer_id, $customer_data, $password_generated) { 
    // My custom function 
} 
+0

這沒什麼區別,原來的wc_create_new_customer函數仍然被調用而不是我的新版本。我懷疑init標籤可能不正確 – fightstarr20 2014-09-03 22:43:27

+0

對不起,我錯過了你實際想要做的事情。看修改後的答案! – gregdev 2014-09-03 23:29:38

+0

但是那麼原來的wc_create_new_customer代碼也不會運行? – fightstarr20 2014-09-04 09:16:27

1

我想知道這個修復,試圖改變標準用戶角色從客戶到定製客戶。這似乎是我可以改變它的唯一方法。

但是,上面的「修復」並不好,因爲它不採用新功能。