Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'woocommerce_before_calculate_totals', [ $this, 'calculate_price' ], 10, 3 );
- add_filter( 'booking_form_calculated_booking_cost', [ $this, 'set_booking_price' ], 10, 3 );
- public function calculate_price( $cart ) {
- if (!is_user_logged_in())
- return;
- if ( is_admin() && ! defined( 'DOING_AJAX' ) )
- return;
- if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
- return;
- $user = wp_get_current_user();
- if( in_array('trusted_customer', (array)$user->roles ) ) {
- foreach ( $cart->get_cart() as $cart_item )
- {
- if( isset($cart_item['booking']) ) {
- $cart_item['data']->set_price(0);
- }
- }
- }
- }
- public function set_booking_price( $booking_cost, $booking, $posted )
- {
- if (!is_user_logged_in()) return;
- $user = wp_get_current_user();
- if( in_array('trusted_customer', (array)$user->roles ) ) {
- $booking_cost = 0;
- }
- return $booking_cost;
- }
Add Comment
Please, Sign In to add comment