Groups (use group/role discounts), by itthinx
Add provided code to functions.php and update Settings.
Calculation option “Use prices modified by other plugins” must be ON.
System option “Suppress other pricing plugins in frontend” must be OFF.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
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; } ); |