WooCommerce 預設會將註冊的使用者角色設為顧客(Customer),但有時候可能會因為一些行銷的需求,或是某種原因,希望將改變預設的使用者角色。如果你只是單純地修改一般設定中的新使用預設角色,是不會有任何作用的。

不過 WooCommerce 提供了一個 filter 讓你可以改變預設的註冊使用者角色。這邊我們將新使用者的角色設為 WP 一般設定中的預設角色。或是你可以直接設定角色的ID(例如vip)。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'woocommerce_new_customer_data', 'my_new_customer_data'); | |
function my_new_customer_data($new_customer_data){ | |
$new_customer_data['role'] = get_option( 'default_role' ); | |
//$new_customer_data['role'] = 'vip'; | |
return $new_customer_data; | |
} |