【问题标题】:Hooking into a WooCommerce filter连接到 WooCommerce 过滤器
【发布时间】:2019-04-05 18:30:24
【问题描述】:

由于最近的 WooCommerce 更新,具有“shopmanager”角色的用户不再能够编辑具有“订阅者”角色的用户。

我发现以下函数对此负责:

function wc_modify_editable_roles( $roles ) {
  if ( is_multisite() && is_super_admin() ) {
    return $roles;
  }
  if ( ! wc_current_user_has_role( 'administrator' ) ) {
    unset( $roles['administrator'] );
    if ( wc_current_user_has_role( 'shop_manager' ) ) {
      $shop_manager_editable_roles = apply_filters( 'woocommerce_shop_manager_editable_roles', array( 'customer' ) );
      return array_intersect_key( $roles, array_flip( $shop_manager_editable_roles ) );
    }
  }
  return $roles;
}
add_filter( 'editable_roles', 'wc_modify_editable_roles' );

我需要将subscriber 添加到apply_filters( 'woocommerce_shop_manager_editable_roles', array( 'customer' ) ); 的数组中,但这就是我卡住的地方。

如何挂钩该过滤器以添加额外角色?

这是我到目前为止所得到的(根本不起作用,但这是一个开始:)

add_filter( 'woocommerce_shop_manager_editable_roles', 'addanotherrole' );

function addanotherrole() {
  $shop_manager_editable_roles = array( 'customer', 'subscriber' );
}

【问题讨论】:

    标签: php wordpress filter woocommerce hook


    【解决方案1】:

    排序!

    你需要像这样返回新的角色数组:

    add_filter( 'woocommerce_shop_manager_editable_roles', 'addanotherrole' );
    function addanotherrole($roles) {
        // add the additional role to the woocommerce allowed roles (customer)
        $roles[] = 'subscriber'; 
    
        // return roles array
        return $roles; 
    

    希望对你有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-12
      • 1970-01-01
      • 1970-01-01
      • 2012-01-22
      • 2017-07-18
      • 1970-01-01
      相关资源
      最近更新 更多