sysins

Returns Roles based discounts when using woocommerce dynamic

Mar 28th, 2013
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. // Returns Roles based discounts when using woocommerce dynamic pricing plugin
  2.  
  3. <?php
  4. function get_the_role_for_user() {
  5. global $current_user;
  6. $current_user = wp_get_current_user();
  7. $user = new WP_User( $current_user->ID );
  8.  
  9. if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
  10. foreach ( $user->roles as $role )
  11. return $role;
  12. }
  13. }
  14.  
  15. function get_the_percentage_discount() {
  16. $role = get_the_role_for_user();
  17. $main_array = get_option('_s_membership_pricing_rules');
  18. foreach ($main_array as $set){
  19. if ($set["conditions"][0]["args"]["roles"][0] == $role){
  20. $amount = $set["rules"][0]["amount"];
  21. return $role.' - '.$amount.'%';
  22. break;
  23. }
  24. }
  25. }
  26.  
  27. $role_percentage = get_the_percentage_discount();
  28. echo $role_percentage;
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment