woocomerce根据订单状态更改用户角色

时间:2018-08-01 00:44:00

标签: wordpress

我已经为此线提供了资金并且可以正常工作,但是我需要一些自定义功能,例如,如果这是注册用户并且该用户不是管理员,并且订单状态为“完成”

<pre>function uiwc_change_role( $order_id ) {
  // get all the order data
  $order = new WC_Order($order_id);

  //get the user email from the order
  $user = $order->get_user();

  // if the this is a registered user and this user is not an admin
  if( false != $user && !user_can($user, 'administrator') ){

    // our new role name
    $role = 'special-customer';

    //set the new role to our customer
    $user->set_role($role);  

  }  
}

//add this newly created function to the thank you page
add_action( 'woocommerce_thankyou', 'uiwc_change_role', 100, 1 );
</pre>

Tnx寻求帮助

0 个答案:

没有答案