add_filter( 'wdp_preloaded_list_user_roles', function ( $list ) { $groups = array(); if ( function_exists( '_groups_get_tablename' ) ) { global $wpdb; $groups_table = _groups_get_tablename( 'group' ); $groups = $wpdb->get_results( "SELECT * FROM $groups_table ORDER BY name" ); } $groups = is_array( $groups ) ? $groups : array(); foreach ( $groups as $group ) { $list[] = array( 'id' => '(group)' . strtolower( $group->name ), 'text' => '(group) ' . $group->name, ); } return $list; } ); add_filter( 'wdp_current_user_roles', function ( $roles ) { $groups = array(); $current_user_id = get_current_user_id(); if ( function_exists( '_groups_get_tablename' ) && $current_user_id ) { global $wpdb; $groups_table = _groups_get_tablename( 'group' ); $user_group_table = _groups_get_tablename( 'user_group' ); $groups = $wpdb->get_results( "SELECT * FROM {$groups_table} WHERE {$groups_table}.group_id IN (SELECT group_id FROM {$user_group_table} WHERE {$user_group_table}.user_id = {$current_user_id} ) ORDER BY name" ); } $groups = is_array( $groups ) ? $groups : array(); foreach ( $groups as $group ) { $roles[] = '(group)' . strtolower( $group->name ); } return $roles; } );
Groups (use group/role discounts), by itthinx Print
Created by: Alex Prokaev
Modified on: Wed, 2 Oct, 2019 at 9:59 AM
Did you find it helpful? Yes No
Send feedbackSorry we couldn't be helpful. Help us improve this article with your feedback.