eventsmanager

Custom placeholder #_BOOKINGPAYPALLINK

May 17th, 2013
160
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. This snippet adds an placeholder called #_BOOKINGPAYPALLINK which displays a link to PayPal for payment of a booking.
  4.  
  5. This is a standard WordPress hook function. For installation instructions of custom snippets see here - http://wp-events-plugin.com/tutorials/how-to-safely-add-php-code-to-wordpress/
  6. */
  7.     add_filter('em_booking_output_placeholder','my_em_get_payment_type',1,3);
  8.     function my_em_get_payment_type($replacement, $EM_Booking, $result){
  9.         if (is_object($EM_Booking)) {
  10.             if ($result == '#_BOOKINGPAYPALLINK') {
  11.                 $count = 1;
  12.                 $url_params = "https://www.paypal.com/cgi-bin/webscr?cmd=_cart&upload=1";
  13.                 $url_params .= "&business=".get_option('em_paypal_email');
  14.                 $url_params .= "&custom=".$EM_Booking->booking_id.':'.$EM_Booking->event_id;
  15.                 $url_params .= "&currency_code=".get_option('dbem_bookings_currency', 'USD');
  16.                
  17.                 //For discount
  18.                 $discount = $EM_Booking->get_price_discounts_amount('pre') + $EM_Booking->get_price_discounts_amount('post');
  19.                 $url_params .= "&discount_amount_cart=".$discount;
  20.                
  21.                 foreach( $EM_Booking->get_tickets_bookings()->tickets_bookings as $EM_Ticket_Booking ){
  22.                     $price = $EM_Ticket_Booking->get_price() / $EM_Ticket_Booking->get_spaces();
  23.                     if( $price > 0 ){
  24.                         $url_params .= "&item_name_".$count."=".wp_kses_data($EM_Ticket_Booking->get_ticket()->name);
  25.                         $url_params .= "&quantity_".$count."=".$EM_Ticket_Booking->get_spaces();
  26.                         $url_params .= "&amount_".$count."=".round($price,2);
  27.                     }
  28.                     $count++;
  29.                 }
  30.                
  31.                 $replacement = "<a href='".$url_params."'>"."Pay Here"."</a>";
  32.             }
  33.         }
  34.         return $replacement;
  35.     }
RAW Paste Data