Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Returns Roles based discounts when using woocommerce dynamic pricing plugin
- <?php
- function get_the_role_for_user() {
- global $current_user;
- $current_user = wp_get_current_user();
- $user = new WP_User( $current_user->ID );
- if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
- foreach ( $user->roles as $role )
- return $role;
- }
- }
- function get_the_percentage_discount() {
- $role = get_the_role_for_user();
- $main_array = get_option('_s_membership_pricing_rules');
- foreach ($main_array as $set){
- if ($set["conditions"][0]["args"]["roles"][0] == $role){
- $amount = $set["rules"][0]["amount"];
- return $role.' - '.$amount.'%';
- break;
- }
- }
- }
- $role_percentage = get_the_percentage_discount();
- echo $role_percentage;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment