/**
  * Return Billing Details
  * 
  * Handles to return billing details for email
  * 
  * @package Social Deals Engine
  * @since 1.0.0
  **/
 public function wps_deals_email_billing_details($data)
 {
     $billingdetailsstr = '';
     if (isset($data['order_details']['billing_details']) && !empty($data['order_details']['billing_details'])) {
         $billingdetails = $data['order_details']['billing_details'];
         //billingcountry
         $billingcountry = isset($billingdetails['country']) ? wps_deals_get_country_name($billingdetails['country']) : '';
         //billing state
         $billingstate = isset($billingdetails['state']) ? wps_deals_get_state_name($billingdetails['state'], $billingdetails['country']) : '';
         //billing company
         $billingcompany = isset($billingdetails['company']) ? $billingdetails['company'] : '';
         //billing adddress
         $billingaddress1 = isset($billingdetails['address1']) ? $billingdetails['address1'] : '';
         $billingaddress2 = isset($billingdetails['address2']) ? $billingdetails['address2'] : '';
         //billing city
         $billingcity = isset($billingdetails['city']) ? $billingdetails['city'] : '';
         //billing postcode
         $billingpostcode = isset($billingdetails['postcode']) ? $billingdetails['postcode'] : '';
         //billing phone
         $billingphone = isset($billingdetails['phone']) ? $billingdetails['phone'] : '';
         $billingdetailsstr .= "\n" . sprintf(__('Address : %s', 'wpsdeals'), $billingaddress1 . "\n" . $billingaddress2);
         $billingdetailsstr .= "\n" . sprintf(__('Company Name : %s', 'wpsdeals'), $billingcompany);
         $billingdetailsstr .= "\n" . sprintf(__('Town / City : %s', 'wpsdeals'), $billingcity);
         $billingdetailsstr .= "\n" . sprintf(__('County / State : %s', 'wpsdeals'), wps_deals_get_state_name($billingstate, $billingdetails['country']));
         $billingdetailsstr .= "\n" . sprintf(__('Zip / Postal Code : %s', 'wpsdeals'), $billingpostcode);
         $billingdetailsstr .= "\n" . sprintf(__('Country : %s', 'wpsdeals'), $billingcountry);
         $billingdetailsstr .= "\n" . sprintf(__('Phone : %s', 'wpsdeals'), $billingcountry);
     } else {
         //$billingdetailsstr .= "\n" . __( 'N / A','wpsdeals');
     }
     return apply_filters('wps_deals_email_billing_details', $billingdetailsstr);
 }
    /**
     * Get Order detail popup details
     * 
     * Handles to get popup view order details
     * 
     * @package Social Deals Engine
     * @since 1.0.0
     */
    public function wps_deals_get_order_popup_details($data)
    {
        ob_start();
        $displayusername = isset($data['userdetails']['first_name']) && !empty($data['userdetails']['first_name']) ? $data['userdetails']['first_name'] . ' ' . $data['userdetails']['last_name'] : $data['userdetails']['user_name'];
        echo '<div id="wps_deal_ordered_' . $data['ID'] . '" class="wps-deals-view-details-wrap">
								<div class="wps-deal-bill-title">' . __('Billing Details', 'wpsdeals') . '</div>';
        echo '<div class="wps-deals-view-bill-details">
							<table>
								<tbody>';
        do_action('wps_deals_sales_admin_header_row_before', $data['ID']);
        echo '						<tr>
										<td><strong>' . __('Purchase Date :', 'wpsdeals') . '</strong></td>
										<td>' . $this->model->wps_deals_get_date_format($data['post_date']) . '</td>
									</tr>
									<tr>
										<td><strong>' . __('Purchase ID :', 'wpsdeals') . '</strong></td>
										<td>' . $data['ID'] . '</td>
									</tr>
									<tr>
										<td><strong>' . __('Buyer Name :', 'wpsdeals') . '</strong></td>
										<td>' . $displayusername . '</td>
									</tr>
									<tr>
										<td><strong>' . __('Buyer Email :', 'wpsdeals') . '</strong></td>
										<td>' . $data['userdetails']['user_email'] . '</td>
									</tr>
									<tr>
										<td><strong>' . __('Payment Method :', 'wpsdeals') . '</strong></td>
										<td>' . $data['payment_method'] . '</td>
									</tr>
									<tr>
										<td><strong>' . __('Payment Status :', 'wpsdeals') . '</strong></td>
										<td>' . $data['payment_status'] . '</td>
									</tr>
									<tr>
										<td><strong>' . __('IP Address :', 'wpsdeals') . '</strong></td>
										<td>' . $data['order_ip'] . '</td>
									</tr>';
        do_action('wps_deals_sales_admin_header_row_after', $data['ID']);
        echo '					</tbody>
							</table>
						</div>';
        //do action to add some content before billing details
        do_action('wps_deals_sales_paymentdetails_before_billing', $data['ID']);
        echo '		<div class="wps-deals-view-bill-details-wrap order-view-bill-details-left">';
        //billing details
        $billingdetails = isset($data['billing_details']) && !empty($data['billing_details']) ? $data['billing_details'] : array();
        //check billing details is not empty
        if (!empty($billingdetails)) {
            //billingcountry
            $billingcountry = isset($billingdetails['country']) ? wps_deals_get_country_name($billingdetails['country']) : '';
            //billing state
            $billingstate = isset($billingdetails['state']) ? wps_deals_get_state_name($billingdetails['state'], $billingdetails['country']) : '';
            //billing company
            $billingcompany = isset($billingdetails['company']) ? $billingdetails['company'] : '';
            //billing adddress
            $billingaddress1 = isset($billingdetails['address1']) ? $billingdetails['address1'] : '';
            $billingaddress2 = isset($billingdetails['address2']) ? $billingdetails['address2'] : '';
            //billing city
            $billingcity = isset($billingdetails['city']) ? $billingdetails['city'] : '';
            //billing postcode
            $billingpostcode = isset($billingdetails['postcode']) ? $billingdetails['postcode'] : '';
            //billing phone
            $billingphone = isset($billingdetails['phone']) ? $billingdetails['phone'] : '';
            echo '		<div class="wps-deals-view-bill-details order-view-bill-details">';
            echo '			<h3>' . __('Billing Details', 'wpsdeals') . '</h3>
							<table>
								<tbody>';
            echo '<tr>
									<td><strong>' . __('Address :', 'wpsdeals') . '</strong></td>
									<td>' . $billingaddress1 . '<br />' . $billingaddress2 . '</td>
								</tr>';
            //do action to add content after billing address
            do_action('wps_deals_order_view_billing_address_after', $data['ID']);
            echo '<tr>
									<td><strong>' . __('Company Name :', 'wpsdeals') . '</strong></td>
									<td>' . $billingcompany . '</td>
								</tr>';
            //do action to add content after billing company name
            do_action('wps_deals_order_view_billing_company_after', $data['ID']);
            echo '<tr>
									<td><strong>' . __('Town / City :', 'wpsdeals') . '</strong></td>
									<td>' . $billingcity . '</td>
								</tr>';
            //do action to add content after billing city
            do_action('wps_deals_order_view_billing_city_after', $data['ID']);
            echo '<tr>
									<td><strong>' . __('County / State :', 'wpsdeals') . '</strong></td>
									<td>' . $billingstate . '</td>
								</tr>';
            //do action to add content after billing county / state
            do_action('wps_deals_order_view_billing_county_after', $data['ID']);
            echo '<tr>
									<td><strong>' . __('Zip / Postal Code :', 'wpsdeals') . '</strong></td>
									<td>' . $billingpostcode . '</td>
								</tr>';
            //do action to add content after billing postcode
            do_action('wps_deals_order_view_billing_postcode_after', $data['ID']);
            echo '<tr>
									<td><strong>' . __('Country :', 'wpsdeals') . '</strong></td>
									<td>' . $billingcountry . '</td>
								</tr>';
            //do action to add content after billing country
            do_action('wps_deals_order_view_billing_country_after', $data['ID']);
            echo '<tr>
									<td><strong>' . __('Phone :', 'wpsdeals') . '</strong></td>
									<td>' . $billingphone . '</td>
								</tr>';
            //do action to add content after billing details after
            do_action('wps_deals_order_view_billing_after', $data['ID']);
            echo '				</tbody>
							</table>
						</div><!--.wps-deals-view-bill-details-->';
        }
        //do action to add some content after billing details
        do_action('wps_deals_sales_paymentdetails_after_billing', $data['ID']);
        echo '</div><!--.wps-deals-view-bill-details-wrap-->';
        //do action to add some content after billing details
        do_action('wps_deals_sales_paymentdetails_after_billing_content', $data['ID']);
        if ($data['payment_method'] == __('PayPal Standard', 'wpsdeals') || $data['payment_method'] == 'paypal') {
            //check payment method
            echo '<div class="wps-deals-view-paypal-details">
					<img src="' . WPS_DEALS_URL . 'includes/images/paypal_logo.gif" />
					<table class="wps-deals-view-paypal-txns" cellspacing="1" cellpadding="1" border="0">
						<tbody>
							<tr>
								<td class="wps-deals-txn-activity" colspan="7">' . __('Transaction Activity', 'wpsdeals') . '</td>
							</tr>
							<tr class="wps-deals-txn-title">
								<td nowrap="nowrap">' . __('Date', 'wpsdeals') . '</td>
								<td nowrap="nowrap">' . __('Name', 'wpsdeals') . '</td>
								<td nowrap="nowrap">' . __('Payer Email', 'wpsdeals') . '</td>
								<td nowrap="nowrap">' . __('Payment Status', 'wpsdeals') . '</td>
								<td nowrap="nowrap">' . __('Gross', 'wpsdeals') . '</td>
								<td nowrap="nowrap">' . __('Fee', 'wpsdeals') . '</td>
								<td nowrap="nowrap">' . __('Net Amount', 'wpsdeals') . '</td>
							</tr>';
            // get the value for the order ipn data from the post meta box
            $paypal_data = $data['ipndata'];
            if (!empty($paypal_data)) {
                $pay_gross = !empty($paypal_data['mc_gross']) ? number_format($paypal_data['mc_gross'], 2) : '0';
                $pay_fees = !empty($paypal_data['mc_fee']) ? number_format($paypal_data['mc_fee'], 2) : '0';
                $net_amount = number_format($pay_gross - $pay_fees, 2);
                $payment_date = $this->model->wps_deals_get_date_format($paypal_data['payment_date']);
                $payment_currency = isset($paypal_data['mc_currency']) ? $paypal_data['mc_currency'] : '';
                $first_name = isset($paypal_data['first_name']) ? $paypal_data['first_name'] : '';
                $last_name = isset($paypal_data['last_name']) ? $paypal_data['last_name'] : '';
                $payer_email = isset($paypal_data['payer_email']) ? $paypal_data['payer_email'] : '';
                $payment_status = isset($paypal_data['payment_status']) ? $paypal_data['payment_status'] : '';
                echo '<tr class="wps-deals-txn-detail">
										<td nowrap="nowrap">' . $payment_date . '</td>
										<td nowrap="nowrap">' . $first_name . ' ' . $last_name . '</td>
										<td nowrap="nowrap">' . $payer_email . '</td>
										<td nowrap="nowrap">' . $payment_status . '</td>
										<td nowrap="nowrap">' . $this->currency->wps_deals_currency_symbol($payment_currency) . ' ' . $pay_gross . '</td>
										<td nowrap="nowrap">' . $this->currency->wps_deals_currency_symbol($payment_currency) . ' ' . $pay_fees . '</td>
										<td nowrap="nowrap">' . $this->currency->wps_deals_currency_symbol($payment_currency) . ' ' . $net_amount . '</td>
									</tr>';
            } else {
                echo '<tr class="wps-deals-txn-detail">
												<td colspan="7">' . __('No PayPal Transaction Information Available', 'wpsdeals') . '</td>
										  </tr>';
            }
            echo '		</tbody>
					</table>
				</div><!--wps-deals-view-paypal-details-->';
        }
        //add some content before payment details
        do_action('wps_deals_sales_paymentdetails_before_items', $data['ID']);
        echo '<div class="wps-deals-view-product-details">
					<div class="wps-deal-bill-title">' . __('Item Ordered', 'wpsdeals') . '</div>
						<table class="widefat fixed">
							<tbody>
								<thead>
									<tr>';
        do_action('wps_deals_sales_order_deatails_header_before', $data['ID']);
        echo '<th>' . __('Name', 'wpsdeals') . '</th>
										<th>' . __('Quantity', 'wpsdeals') . '</th>
										<th>' . __('Price', 'wpsdeals') . '</th>
										<th>' . __('Total', 'wpsdeals') . '</th>';
        do_action('wps_deals_sales_order_deatail_header_after', $data['ID']);
        echo '</tr>
								</thead>';
        $alternate = '';
        foreach ($data['deals_details'] as $deal) {
            echo '<tr ' . $alternate . '>';
            do_action('wps_deals_sales_order_details_data_before', $data['ID']);
            echo '<td>' . get_the_title($deal['deal_id']) . '</td>
									
									<td>' . $deal['deal_quantity'] . '</td>
									
									<td>' . $deal['display_price'] . '</td>
									
									<td>' . $deal['display_total'] . '</td>';
            do_action('wps_deals_sales_order_details_data_after', $data['ID']);
            echo '</tr>';
            $alternate = $alternate ? '' : 'class="alternate"';
        }
        do_action('wps_deals_sales_popup_order_row_after', $data['ID']);
        echo '<tr class="alternate">
							
							<td colspan="2"></td>
							
							<td>' . __('Sub Total', 'wpsdeals') . '</td>
							
							<td>' . $data['display_order_subtotal'] . '</td>
							
						</tr>';
        do_action('wps_deals_sales_popup_order_row_after_subtotal', $data['ID']);
        //check fees is set in order data and not empty
        if (isset($data['fees']) && !empty($data['fees'])) {
            foreach ($data['fees'] as $fee_key => $fee_val) {
                echo '<tr>
									<td colspan="2"></td>
									<td>' . $fee_val['label'] . '</td>
								  	<td>' . $fee_val['display_amount'] . '</td>
								  </tr>';
            }
            //end foreach loop
        }
        //end if to check there is fees is exist in order or not
        //do action to add something in backed order popup details after fees row
        do_action('wps_deals_sales_popup_order_row_after_fees', $data['ID']);
        echo '<tr class="alternate">
											
							<td colspan="2"></td>
							
							<td>' . __('Total', 'wpsdeals') . '</td>
							
							<td>' . $data['display_order_total'] . '</td>
							
						</tr>';
        echo '		</tbody>
				</table>';
        echo '	</div><!--wps-deals-view-product-details-->';
        //add some content after payment details
        do_action('wps_deals_sales_paymentdetails_after_items', $data['ID']);
        echo '		</div><!--.wps-deals-view-details-wrap-->';
        return ob_get_clean();
    }
 /**
  * My Account Billing Address
  * 
  * Handles to show my account billing address
  * 
  * @package Social Deals Engine
  * @since 1.0.0
  **/
 function wps_deals_my_account_billing_address($key, $title)
 {
     global $current_user, $wps_deals_options;
     //check billing is enable from settings page
     if (isset($wps_deals_options['enable_billing']) && !empty($wps_deals_options['enable_billing'])) {
         $prefix = WPS_DEALS_META_PREFIX;
         //get user billing data saved
         $userbillingdata = get_user_meta($current_user->ID, $prefix . 'billing_details', true);
         //get user country from saved
         $usercountry = isset($userbillingdata['country']) ? wps_deals_get_country_name($userbillingdata['country']) : '';
         //get user state or county
         $userstate = isset($userbillingdata['state']) ? wps_deals_get_state_name($userbillingdata['state'], $userbillingdata['country']) : '';
         //get user company name
         $usercompany = isset($userbillingdata['company']) ? $userbillingdata['company'] : '';
         //get user address1
         $useraddress1 = isset($userbillingdata['address1']) ? $userbillingdata['address1'] : '';
         //get user address2
         $useraddress2 = isset($userbillingdata['address2']) ? $userbillingdata['address2'] : '';
         //get user city or town
         $usercity = isset($userbillingdata['city']) ? $userbillingdata['city'] : '';
         //get user post code
         $userpostcode = isset($userbillingdata['postcode']) ? $userbillingdata['postcode'] : '';
         //get user phone
         $userphone = isset($userbillingdata['phone']) ? $userbillingdata['phone'] : '';
         //data pased to template
         $billingargs = array('billingkey' => $key, 'billingtitle' => $title, 'billingcountry' => $usercountry, 'billingstate' => $userstate, 'billingcompany' => $usercompany, 'billingaddress1' => $useraddress1, 'billingaddress2' => $useraddress2, 'billingcity' => $usercity, 'billingpostcode' => $userpostcode, 'billingphone' => $userphone, 'billingalldata' => $userbillingdata);
         //billing details template
         do_action('wps_deals_display_address', $billingargs);
     }
     //end if to check enable billing or not
 }
    do_action('wps_deals_order_view_footer_row_after', $order_id);
    ?>
			</tfoot>
		
		</table>
<?php 
    /**
     * wps_deals_order_view_ordered_deals_after hook
     */
    do_action('wps_deals_order_view_ordered_deals_after', $order_id);
    //billing details
    $billingdetails = isset($order_details['billing_details']) ? $order_details['billing_details'] : array();
    // check billing details not empty
    if (!empty($billingdetails)) {
        //billingcountry
        $billingcountry = isset($billingdetails['country']) ? wps_deals_get_country_name($billingdetails['country']) : '';
        //billing state
        $billingstate = isset($billingdetails['state']) ? wps_deals_get_state_name($billingdetails['state'], $billingdetails['country']) : '';
        //billing company
        $billingcompany = isset($billingdetails['company']) ? $billingdetails['company'] : '';
        //billing adddress
        $billingaddress1 = isset($billingdetails['address1']) ? $billingdetails['address1'] : '';
        $billingaddress2 = isset($billingdetails['address2']) ? $billingdetails['address2'] : '';
        //billing city
        $billingcity = isset($billingdetails['city']) ? $billingdetails['city'] : '';
        //billing postcode
        $billingpostcode = isset($billingdetails['postcode']) ? $billingdetails['postcode'] : '';
        //billing phone
        $billingphone = isset($billingdetails['phone']) ? $billingdetails['phone'] : '';
        ?>