Guest User

Untitled

a guest
Jan 16th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. add_action( 'woocommerce_before_calculate_totals', [ $this, 'calculate_price' ], 10, 3 );
  2. add_filter( 'booking_form_calculated_booking_cost', [ $this, 'set_booking_price' ], 10, 3 );
  3.  
  4. public function calculate_price( $cart ) {
  5. if (!is_user_logged_in())
  6. return;
  7.  
  8. if ( is_admin() && ! defined( 'DOING_AJAX' ) )
  9. return;
  10.  
  11. if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
  12. return;
  13.  
  14. $user = wp_get_current_user();
  15.  
  16. if( in_array('trusted_customer', (array)$user->roles ) ) {
  17. foreach ( $cart->get_cart() as $cart_item )
  18. {
  19. if( isset($cart_item['booking']) ) {
  20. $cart_item['data']->set_price(0);
  21. }
  22. }
  23. }
  24. }
  25.  
  26. public function set_booking_price( $booking_cost, $booking, $posted )
  27. {
  28. if (!is_user_logged_in()) return;
  29.  
  30. $user = wp_get_current_user();
  31.  
  32. if( in_array('trusted_customer', (array)$user->roles ) ) {
  33. $booking_cost = 0;
  34. }
  35.  
  36. return $booking_cost;
  37. }
Add Comment
Please, Sign In to add comment