<?php
ob_start();
/**
 * Plugin Name:  WooCommerce Cart PDF Quote
 * Description:  Allows customers to download their cart as a PDF
 * Version:      1.0.4
 * Author:       Seattle Web Co.
 * Author URI:   https://bytelabz.com
 * Text Domain:  wc-cart-pdf
 * Domain Path:  /languages/
 * Contributors: seattlewebco, dkjensen
 * Requires PHP: 5.3.6
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */



if( ! defined( 'ABSPATH' ) ) {
    exit;
}

define( 'WC_CART_PDF_PATH', plugin_dir_path( __FILE__ ) );


require WC_CART_PDF_PATH . 'vendor/autoload.php';
require WC_CART_PDF_PATH . 'wc-cart-pdf-compatibility.php';

if( isset($_POST['generate_posts_pdf'])){

   $_SESSION['p_name']=$_POST['p_name'];
        $_SESSION['p_email']=$_POST['p_email'];
           $_SESSION['p_email2']=$_POST['p_email2'];
            $_SESSION['p_location']=$_POST['p_location2'];
            $_SESSION['p_company']=$_POST['p_company'];
                $_SESSION['p_message']=$_POST['p_message'];
                $_SESSION['handling']= $_POST['q_handling'];
                $_SESSION['handling-int']= $_POST['handling-fee-for-streamer'];
                $_SESSION['special-str']= $_POST['special-shipping-fee'];
$_SESSION['shipping-25-off']= $_POST['q_shipping-25-off'];


   // pdf_download();
    add_action( 'template_redirect','pdf_download');
}


function pdf_download(){

    // Do stuff. Say we will echo "Fired on the WordPress initialization".
   // echo 'Fired on the WordPress initialization';
	ob_start();
    $dompdf = new \Dompdf\Dompdf();

	//$dompdf->loadHtml( '<html>haii'.$_SESSION['p_name'].' jdjdj'.$_SESSION['p_email'].'</html>');

    $content = $css = '';

    $cart_table = wc_locate_template( 'cart-table.php', '/woocommerce/wc-cart-pdf/', __DIR__ . '/templates/' );
    $css        = wc_locate_template( 'pdf-styles.php', '/woocommerce/wc-cart-pdf/', __DIR__ . '/templates/' );
	//echo $cart_table; die;
    do_action( 'wc_cart_pdf_before_process' );

    if( file_exists( $cart_table ) ) {
        ob_start();
        include $cart_table;		
        $content = ob_get_clean();		
		
    }
    
    if( file_exists( $css ) ) {
        ob_start();
        include $css;
        $css = apply_filters( 'woocommerce_email_styles', ob_get_clean() );		
		
    }
  
    $dompdf->loadHtml( '<style>' . $css . '</style>' . $content );





		$dompdf->setPaper( 'A4', 'portrait' );

		$dompdf->render();



		$dompdf->stream( 
				apply_filters( 'wc_cart_pdf_filename', 'WC_Cart-' . date( 'Ymd' ) . bin2hex( openssl_random_pseudo_bytes( 5 ) ) ) . '.pdf', 
				
				/**
				 * 'compress' => 1 or 0 - apply content stream compression, this is on (1) by default
				 * 'Attachment' => 1 or 0 - if 1, force the browser to open a download dialog, on (1) by default
				 */ 
				apply_filters( 'wc_cart_pdf_stream_options', array( 'compress' => 1, 'Attachment' => 1 ) ) 
			);

		echo "end!";exit;

}




add_action( 'init', 'process_post' );
 
function process_post() {
     ob_start();
}

function wpse_load_plugin_css() {
    $plugin_url = plugin_dir_url( __FILE__ );
    if( !session_id() ){
        session_start();
    }
    wp_enqueue_style( 'style1', $plugin_url . 'css/style1.css' );

}
add_action( 'wp_enqueue_scripts', 'wpse_load_plugin_css' );

add_action('woocommerce_cart_totals_before_order_total','wl_handle');
function wl_handle($method){
   echo "<div id='cont-append'>";
    foreach ( WC()->cart->get_fees() as $fee ) { ?> 
    <?php //print_r($fee);?>
      <input class="form-control bccolor hide-fee" style="display: none;" placeholder="handling fee"  id="q_<?php echo esc_html( $fee->id ); ?>" name="q_<?php echo esc_html( $fee->id ); ?>" value="<?php echo '$'.esc_html( $fee->total ); ?>" size="40" type="text">  
 
 <?php  }  

 echo "</div>";



}


add_action('woocommerce_proceed_to_checkout','add_to_quote_note');
function add_to_quote_note(){
  echo '<p class="quote-note" style="color:white!important;">If placing an International order, We may be able to find a more economical shipping price for you. Please click the "Get a Quote" button below & we will provide an estimate.</p>';
}


add_action('woocommerce_after_cart','add_to_quote');

function add_to_quote(){ 

echo '<div class="add-qtip"><button type="submit" id="trigger_cf" class="wc-forward cart-continue checkout-button button alt single_add_to_cart_button button alt">Click to Get Quote</button> <div class="help-tip">';



echo "<p>For Quotes with multiple items.</br>If you are adding multiple items, press Continue Shopping and add additional items to your cart. Once you have  all of your items in your cart, then press <strong>Click to Get Quote</strong>, and you'll receave a quote for all of your items (including tax, shipping and handling).</br><strong>For quotes for international customers, inquire to <a href='mailto:orders@success4kidswhl.com'>orders@success4kidswhl.com</a></strong>.</p> 
</div>";


echo '<div id="q_loading_img"></div></div>';





echo '<div id="product_inq" style="display:none">';
echo '</br><h2> Request For Quote</h2>';
 ?>

<form id="add-sub" method="post"  enctype="multipart/form-data">
     <h3>Please fill in the details so we can include them in your quote document.</h3>
     <h3>Select Download Quote as PDF or Request Email Quote when complete.</h3>
     <div class="row">
     <div class="col-sm-6">
         <label>Name:</label>
      <input class="form-control bccolor" name="p_name" placeholder="Enter the Name" required id="name" value="" size="40" aria-required="true" aria-invalid="false" type="text">
    </div>
     <div class="col-sm-6">
         <label>Enter the Email Address:</label>
     <input class="form-control bccolor" name="p_email" placeholder="Email" required id="email" value="" size="40" aria-required="true" aria-invalid="false" type="email">
    </div>
    
  </div>
  <div class="row">
    <div class="col-sm-12">
         <label>location:</label>
     <input class="form-control bccolor" name="p_location" placeholder="Enter your location" required id="location" value="" size="40" aria-required="true" aria-invalid="false" type="text" disabled>
     <input  name="p_location2" id="location2" value=""  type="hidden">
    </div>
     <div class="col-sm-12">
          <label>Company Name:</label>
     <input class="form-control bccolor" name="p_company" placeholder="Enter Company Name" id="company_name" value="" size="40" aria-required="true" aria-invalid="false" type="text">
    </div>
    <div class="col-sm-12">
        <label>Mailing Address:</label>
     <input class="form-control bccolor" name="p_email2" placeholder="Enter Full Mailing Address" required id="email2" value="" size="40" aria-required="true" aria-invalid="false" type="text">
    </div>
    <div class="col-sm-12">
        <label>Specify the Product item(s):</label>
    <textarea class="form-control bccolor" name="p_message" placeholder="Specify the product item(s) to be included in your purchase quote" id="message" cols="38" rows="6" aria-invalid="false"></textarea>
    </div>
  </div>


<div id='cont-append2'></div>

<?php if('0'){

 foreach ( WC()->cart->get_fees() as $fee ) { ?> 
    <?php //print_r($fee);?>
     <input class="form-control bccolor hide-fee" style="display: none;" placeholder="handling fee"  id="p_<?php echo esc_html( $fee->id ); ?>" name="<?php echo esc_html( $fee->id ); ?>" value="<?php echo '$'.esc_html( $fee->total ); ?>" size="40" type="text">
    
  <?php }  } 

      

//$data = wp_nonce_url('download_quote');    
//$wp_once = substr($data, strpos($data, "=") + 1);    
//echo $wp_once; ?>
<input type="hidden" name="action" value="wc_cart_pdf_process_download">
<input type="hidden" name="cart-pdf" value="1">
<?php wp_nonce_field('my_delete_action'); ?>
<!--<button id="sh" type="submit">print</button>-->

<!---<div class="col-sm-6">
    <button class="button button-primary" id="generate_pdf" type="submit" name="generate_posts_pdf" value="generate">Download Quote as PDF</button>
</div>-->

</form>



<!--<button id="share-pop">submit</button>-->
<div class="col-sm-6">
     <button id="share-popp" type="submit">Send Email</button>
      <?php $base_url=site_url(); ?>
     <img id='ajx-loader' src='<?php echo $base_url; ?>/wp-content/plugins/wc-cart-pdf-quote/image/ajax-loader-blue.gif' alt='ajax-loading' style='display:none' />
     
</div>


<?php if(0){ ?>
   <a id="print_to" href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'cart-pdf' => '1' ), wc_get_cart_url() ), 'cart-pdf' ) );?>" class="cart-pdf-button button" target="_blank">
            <?php esc_html_e( 'Download Quote as PDF', 'wc-cart-pdf' ); ?>
        </a>

  <?php }

  echo '</div>';


 
?>
<script type="text/javascript">
jQuery(document).ready(function(){
  jQuery.ajaxPrefilter(function( options, original_Options, jqXHR ) {
    options.async = true;
});
});
jQuery('#generate_pdf').on('click', function(){

     var jah = jQuery('#q_handling').val();
     var jahksmd = jQuery('#q_handling-fee-for-streamer').val();
     var spc = jQuery('#q_special-shipping-fee').val();
   //alert(jahksmd);
   jQuery("#p_handling").val(jah);
   jQuery("#p_handling-fee-for-streamer").val(jahksmd);
   jQuery('#p_special-shipping-fee').val(spc);

});

/*jQuery(document).ready(function(){
    // Attach a click event handler to the "Update" button
  
    jQuery('button[name="calc_shipping"]').on('click', function(event){
         console.log('jh');
         // populateLocationField();
       return true;
       
    });
});

 */   function populateLocationField() {
        var shipstate = jQuery("#calc_shipping_state").find(":selected").text();
        var calc_shipping_city = jQuery("#calc_shipping_city").val();
        var calc_shipping_postcode = jQuery("#calc_shipping_postcode").val();
        var state_code = jQuery("#calc_shipping_state").val();
        var titleCountry = jQuery("#calc_shipping_country").find(":selected").text();

        // Concatenate the location values
        var locationValue = calc_shipping_city + ', ' + shipstate + ', ' + state_code + ' ' + calc_shipping_postcode + ', ' + titleCountry;

        // Set the concatenated value as the value of the "location" field
        jQuery("#location").val(locationValue);
        jQuery("#location2").val(locationValue);
    }
jQuery(document).ready(function(){
    // Detect changes in address fields and refresh the cart page
    jQuery(document).on('change', 'input[name^="calc_shipping"], select[name^="calc_shipping"]', function(){
       populateLocationField();
       if (jQuery('#trigger_cf').text().trim() === "Close") {
        // Trigger a click event on the button with ID "trigger_cf"
        jQuery('#trigger_cf').click();
        setTimeout(function(){
            console.log("after")
      jQuery(".wc-proceed-to-checkout .checkout-button").hide();
        }, 500);
    }
    });
});
        jQuery('#trigger_cf').on('click', function(){
        
        var append1 =jQuery( "#cont-append" ).html();
          jQuery("#cont-append2").html(append1);
      jQuery('#q_loading_img').show();
 jQuery('#q_loading_img').delay(1000).fadeOut();
 
 var shipstate=jQuery("#calc_shipping_state").find(":selected").text();
 var calc_shipping_city=jQuery("#calc_shipping_city").val();
 var calc_shipping_postcode=jQuery("#calc_shipping_postcode").val();
 var state_code = jQuery("#calc_shipping_state").val();
var titleCountry = jQuery("#calc_shipping_country").find(":selected").text();

 // Concatenate 
var locationValue = calc_shipping_city+ ', ' + shipstate + ', '+ state_code + ' ' + calc_shipping_postcode +', ' + titleCountry;

jQuery("#location").val(locationValue);

                        if (jQuery("#calc_shipping_state").val() == "") {
                           
                            alert('Please select your shipping Location');
                            jQuery('#q_loading_img').hide();
                            return false;
  
                          }

                      if ( jQuery(this).text() == 'Click to Get Quote' ) {
                                   jQuery('#product_inq').css("display","block");
                                   jQuery("#trigger_cf").html('Close'); 
                                
                      } else {
                         jQuery('#product_inq').hide();

                         jQuery("#trigger_cf").html('Click to Get Quote'); 
                     
                         
                      }

       
        });
        

jQuery('#print_to').click(function(){

if (jQuery('#name').val() == ""){
alert('Please complete the Name field');
return false;
}
var name =  jQuery('#name').val();
if(jQuery('#email').val() == ''){
alert('Please complete the Email field');
return false;
}
if(jQuery('#location').val() == ''){
alert('Please complete the Location field');
return false;
}
var email =  jQuery('#email').val();
if(IsEmail(email)==false){
alert('Invalid Email');
return false;
}
var q_shipping =  jQuery('#q_shipping-25-off').val();
var handling =  jQuery('#q_handling').val();
var location =  jQuery('#location').val();
var message =  jQuery('#message').val();

jQuery.ajax({
            type: "POST",
            url: '<?php echo admin_url('admin-ajax.php'); ?>',
            data: {"action" : "diplay_user_table",
            message: message,
            name: name,
            email: email,
            location:location,
             handling:handling,
            q_shipping:q_shipping
        },
            success: function( response ){  
                console.log(response);
            console.log("print successfuly..");
           
             },
             error: function( error ){
            console.log('AJAX error callback....');
            //console.log(error);
        }
        });

});  


jQuery('#share-popp').click(function(){



    if (jQuery('#name').val() == ""){
          alert('Please complete the Name field');
          return false;
        }

     var name =  jQuery('#name').val();

     if(jQuery('#email').val() == ''){
          alert('Please complete the Email field');
          return false;
        }

        if(jQuery('#location').val() == ''){
          alert('Please complete the Location field');
          return false;
        }

         if(jQuery('#email2').val() == ''){
          alert('Please complete the Address field');
          return false;
        }

     var email =  jQuery('#email').val();

        if(IsEmail(email)==false){
          alert('Invalid Email');
          return false;
        }
    var email2 =  jQuery('#email2').val();
    
    

      var q_shipping =  jQuery('#q_shipping-25-off').val();  
      var handling =  jQuery('#q_handling').val();
      var location =  jQuery('#location').val();
      var message =  jQuery('#message').val();
      var specialshippingfee = jQuery('#q_special-shipping-fee').val();
      var handlingfeeforstreamer = jQuery('#q_handling-fee-for-streamer').val();
     var comapny_name = jQuery('#company_name').val();
       
       jQuery("#ajx-loader").show();

        jQuery.ajax({
            type: "POST",
            url: '<?php echo admin_url('admin-ajax.php'); ?>',
            data: {"action" : "callback_send_email",
            message: message,
            name: name,
            email: email,
            location:location,
            email2:email2,
            handling:handling,
            specialshippingfee:specialshippingfee,
            handlingfeeforstreamer:handlingfeeforstreamer,
             q_shipping:q_shipping,
             comapny_name:comapny_name
        },
            success: function( response ){  
                jQuery("#ajx-loader").hide();

            //console.log("This is response...");
            alert(" Quote Sent Successfully..")
            console.log(response);
             },
             error: function( error ){
            
            jQuery("#ajx-loader").show();
            alert("Quote Sending Failed")
            console.log(error);
        }
        });
    });
 function IsEmail(email) {
  var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  if(!regex.test(email)) {
    return false;
  }else{
    return true;
  }
}

    </script>

<?php  }

add_action('wp_ajax_diplay_user_table', 'diplay_user_table');
add_action('wp_ajax_nopriv_diplay_user_table', 'diplay_user_table');
function diplay_user_table() {


//wc_cart_pdf_process_download($_REQUEST['name'],$_REQUEST['email'],$_REQUEST['message'],$_REQUEST['location']);

 
 if(session_id() == ''){
     session_start();
}
      
if(session_id() != '')
        {
         $_SESSION['name'] = $_REQUEST['name'];
         $_SESSION['email'] = $_REQUEST['email'];
         $_SESSION['message']= $_REQUEST['message']; 
         $_SESSION['location']= $_REQUEST['location'];
         $_SESSION['handling']= $_REQUEST['handling'];
         $_SESSION['messagetest']= $_REQUEST['messagetest'];
    }
        //echo $name;

      //print_r(session_id());

    
}



add_shortcode( 'diplay_user_table2', 'diplay_user_table2' );

function diplay_user_table2() 
{
     
 if(session_id() == ''){
     session_start();
}


return  '<div class="customer-details">
      <h2>Customer Details</h2>
      <table border="0"><tbody>

      <tr><td> Name: </td><td>' . $_SESSION['name']. '</td></tr> 
       <tr><td> Email: </td><td>' . $_SESSION['email']. '</td></tr> 
       <tr><td> Location: </td><td>' . $_SESSION['location']. '</td></tr> 
       <tr><td> Message: </td><td>' . $_SESSION['message']. '</td></tr> 

     
      </tbody> </table> </div>' ;

    wp_die();
}

add_shortcode( 'diplay_handling', 'diplay_handling' );

function diplay_handling() {
 if($_SESSION['handling']!='')
 {

   return '<tr class="fee">
                <th class="row-subtotal" colspan="4" style="text-align: right;">Handling</th>
<td class="row-subtotal" data-title="<?php echo esc_attr( $fee->name ); ?>">'.$_SESSION['handling'].'</td>';
     
 }

}



add_action( 'wp_ajax_callback_send_email', 'callback_send_email' );
add_action( 'wp_ajax_nopriv_callback_send_email', 'callback_send_email' );

function wpse27856_set_content_type(){
    return "text/html";
}
add_filter( 'wp_mail_content_type','wpse27856_set_content_type' );

function callback_send_email(){
?>
<?php 

 $table = '<html><body>';
 $base_url=site_url();
  $table = "<img src='$base_url/wp-content/themes/sfk/assets/images/logo.jpg' alt='defaultImage' />";
$em_handling_int=0;
 $table .='<form>';
         $name = $_REQUEST['name'];
         $c_email = $_REQUEST['email'];
         $c_email2 = $_REQUEST['email2'];
        $message= $_REQUEST['message'];
        $location= $_REQUEST['location'];
        $em_handling = $_REQUEST['handling'];
        $em_handling_int = $_REQUEST['handlingfeeforstreamer'];
        $em_special_ship= $_REQUEST['specialshippingfee'];
        $em_shipping_off = $_REQUEST['q_shipping'];
        $em_comapny_name = $_REQUEST['comapny_name'];

 $table .="<div class='customer-details'>";
 $table .="<h2>Customer details</h2>";

 $table .="<table border='0'>";
 $table .="<tbody>";
  
 
$table .="<tr><td> Name: </td><td>".$name."</td></tr>";
$table .="<tr><td> Email: </td><td>".$c_email."</td></tr>";
$table .="<tr><td> Location: </td><td>".$location."</td></tr>";
$table .="<tr><td> Company Name: </td><td>".$em_comapny_name."</td></tr>";
$table .="<tr><td> Full Mailing Address: </td><td>".$c_email2."</td></tr>";
$table .="<tr><td> Message: </td><td>".$message."</td></tr>";



$table .="</tbody>" ;
 $table .="</table>";

 $table .="</div>";
$table .="<h2>Quote details</h2>";
 $table .="<center><table border='1' class='shop_table shop_table_responsive cart woocommerce-cart-form__contents' cellspacing='0'>"; 
    $table .="<thead>"; 
        $table .=" <tr>"; 
         $table .="<th> SI NO </th>";
          $table .="<th class='product-name'>Product</th>";
           $table .="<th class='product-price'>Price</th>";
           $table .=" <th class='product-quantity'>Quantity</th>";
           $table .=" <th class='product-subtotal'>Total</th>";
        $table .=" </tr>";
     $table .="</thead>";

   $table .="<tbody>" ;
$si=1;
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
  $_product   = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
  $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_cart_item_visible', true, $cart_item, $cart_item_key ) ) {

  $product_permalink = apply_filters( 'woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '', $cart_item, $cart_item_key );
     $table .="<tr>";

     $table .="<td>".$si."</td>";

 $table .="<td class='product-name'>";

                      if ( ! $product_permalink ) {
                        $ml_prod= wp_kses_post( apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key ) . '&nbsp;' );
                    } else {
                        $ml_prod= wp_kses_post( apply_filters( 'woocommerce_cart_item_name', sprintf( '<a href="%s">%s</a>', esc_url( $product_permalink ), $_product->get_name() ), $cart_item, $cart_item_key ) );
                    }

   $table .=$ml_prod;    
   $table .="</td> <td class='product-price'>";


    $ml_price  = apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key ); 

    $table .= $ml_price;

   $table .="</td> <td class='product-qty'>";

    
    $ml_qty=esc_html( $cart_item['quantity'] );

  $table .= " ".$ml_qty;

  $table .="</td> <td class='product-total'>";

       $ml_price_tot = apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key );

   $table .= $ml_price_tot; 

   $table .="</td>";

   $table .="</tr>";
         /*$ml_subtotal+= $ml_price_tot*$ml_qty; 
         $s_tot=wc_price( $ml_subtotal ); */
                         }            
$si++; }

   $table .="<tr>";

   $table .="<th class='row-subtotal' colspan='4' style='text-align: right;'>Subtotal</th> <td class='row-subtotal' data-title='Subtotal'>";
   

    $ml_subtot=WC()->cart->get_cart_subtotal();
    $table .= $ml_subtot;

    $table .="</td></tr>";
  
     
       


          $ship=0;
          $hand=0;
       

         if ($em_handling !='') {
           $hand=$em_handling;
          $hand_int=$em_handling_int;

           
     

         
        if ( 0 < WC()->cart->get_shipping_total() ){
         $ship=WC()->cart->get_shipping_total();
            }
         $hand_val=str_replace("$","",$hand);
         $hand_val_int=str_replace("$","",$hand_int);
        $handling_val=(float)$hand_val;
        $handling_val_int=(float)$hand_val_int;
        $hand_rus=$handling_val+$handling_val_int;
        $ship_hand=$ship+$hand_rus;

         $table .="<tr class='fee'>";
        $table .= "<th colspan='4' style='text-align: right;'>";
        $table .= "Shipping & Handling";
        $table .= " </th>";
        $table .= "<td> $";
      
      $table .=  $ship_hand;

      $table .= "</td></tr>";
           }  
           else {

     if ( 0 < WC()->cart->get_shipping_total() ) :
          
    $table .="<tr class='shipping'>";
    $table .="<th colspan='4' style='text-align: right;'>Shipping/Handling:</th> <td>";
    $ml_shiptot = WC()->cart->get_cart_shipping_total();
    $table .= $ml_shiptot;
    $table .= "</td></tr>";

         //endif; 
        //elseif ( 0 == WC()->cart->get_shipping_total() &&  ( WC()->cart->has_discount( 'purchaseordersale' ) || WC()->cart->has_discount( 'purchaseordercoupon' ) )) :
          elseif ( 0 == WC()->cart->get_shipping_total() && ( count( WC()->cart->get_applied_coupons() ) > 0 )) :
       $table .="<tr class='shipping'>";        
     $table .="<th colspan='4' style='text-align: right;'>Discount</th> <td>";
    $ml_coup = 'Coupon Applied';
    $table .= $ml_coup;
     $table .= "</td></tr>";
    $table .="<tr class='shipping'>";
   
    $table .="<th colspan='4' style='text-align: right;'>Shipping/Handling:</th> <td>";
    $ml_shiptot = 'TBD';
    $table .= $ml_shiptot;
    $table .= "</td></tr>";

         endif; 
           }
          
if($em_special_ship !=''){


  $table .="<tr class='fee'>";
        $table .= "<th colspan='4' style='text-align: right;'>";
        $table .= "Special Shipping Fee";
        $table .= " </th>";
        $table .= "<td>";
      
      $table .=  $em_special_ship;

      $table .= "</td></tr>";

}
   if ($em_shipping_off !='') {
                
                $shopoff=$em_shipping_off;
        $shopoff_val=str_replace("$","",$shopoff);
        $shopoff_val_val=(float)$shopoff_val;
        $shopoff_val_val_hand=$shopoff_val_val;

        $table .="<tr class='fee'>";
        $table .= "<th colspan='4' style='text-align: right;'>";
        $table .= "Shipping 25% Off";
        $table .= " </th>";
        $table .= "<td>";
        $table .= "$".$shopoff_val_val_hand;
        $table .= "</td></tr>";

           }
      

   foreach ( WC()->cart->get_fees() as $fee ) : 
      

      $table .="<tr class='fee'>";
        $table .= "<th colspan='4' style='text-align: right;'>";
        $table .= $fee->name;
        $table .= " </th>";
        $table .= "<td>";
      
      $table .=  $fee->amount;

      $table .= "</td></tr>";

  endforeach;
$tax_rate=0;
  if ( wc_tax_enabled() && ! WC()->cart->display_prices_including_tax()  ) :
      $taxable_address = WC()->customer->get_taxable_address();
      $estimated_text  = WC()->customer->is_customer_outside_base() && ! WC()->customer->has_calculated_shipping()
          ? sprintf( ' <small>' . __( '(estimated for %s)', 'woocommerce' ) . '</small>', WC()->countries->estimated_for_prefix( $taxable_address[0] ) . WC()->countries->countries[ $taxable_address[0] ] )
          : '';


          if ( 'itemized' === get_option( 'woocommerce_tax_total_display' ) ) : 
         foreach ( WC()->cart->get_tax_totals() as $code => $tax ) : 
          $table .= "<tr class='tax-rate tax-rate'>";
          $table .= "<th class='row-subtotal' colspan='4' style='text-align: right;''>";

           $table .= esc_html( $tax->label );
           $table .= $estimated_text; 

            $table .= "</th>";

            $table .= "<td class='row-subtotal' data-title='echo esc_attr( $tax->label );'>";

           // $tax_rate = wp_kses_post( $tax->formatted_amount );
             $tax_rate = wc_format_decimal($tax->amount);
            if(!(count( WC()->cart->get_applied_coupons()) ) > 0  ){
             $table .=  wc_price($tax_rate);
            }
            else 
            {
                $table .=  wc_price('0');
            }
            $table .= "</td></tr>";
        endforeach;
       else : 
         $table .= "<tr class='tax-total'>";
         $table .= "<th class='row-subtotal' colspan='4' style='text-align: right;'> ";

          $table .= " esc_html( WC()->countries->tax_or_vat() )";
           $table .= $estimated_text; 
            $table .= "</th>";

           $table .= "<td class='row-subtotal'>";

            $table .= wc_cart_totals_taxes_total_html();  
         
          $table .= "</td></tr>";

         endif; 
         endif; 


$carttotal=0;
       $table .="<tr class='order-total'>";
       $table .="<th colspan='4' style='text-align: right;'>Total</th> <td>";
       $carttotal=WC()->cart->total;
     if(!(count( WC()->cart->get_applied_coupons()) ) > 0  ){
         $ml_total =  WC()->cart->total;
     }
     else
     {
        $ml_total = $carttotal-$tax_rate;
     }
       $table .= wc_price($ml_total);
       $table .= "</td></tr>";



   $table .="</tbody>";

   $table .= "</table></center></form>";
$table .='<center><p>Thank you for your interest in Supporting Success for Children with Hearing Loss.</p>
    <p>Supporting Success for Children with Hearing Loss</p>
    <p>12094 Anderson Road, Suite 347</p>
    <p>Tampa, FL 33625</p>
    <p><a href="tel:(888) 963-8991">(888) 963-8991</a></p>
    <p>Contact: <a href="mailto:orders@success4kidswhl.com">orders@success4kidswhl.com</a></p>
    <p>Website: <a href="https://successforkidswithhearingloss.com">SuccessForKidsWithHearingLoss.com</a></p></center>';
     $table .= "</body></html>";

        $admin_maill = get_option('admin_email');
    //  $admin_email1 = 'nithin@bytelabz.com';
      $admin_email1 = 'accounting@success4kidswhl.com,orders@success4kidswhl.com';
        // Return a boolean!
        $to = $c_email;
      
        $subject = "Your Quote from Supporting Success For Children With Hearing Loss";
        $message = $table;
       
    //    $headers  = "MIME-Version: 1.0" . "\r\n";
     //   $headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
        
         $headers = "From: quotes@successforkidswithhearingloss.com" . "\r\n" ;
        
        $headers .= "Reply-To: questions@success4kidswhl.com" . "\r\n";
        $headers .= "Cc: $admin_email1 \r\n";


  /*        if(wp_mail($to,$subject,$message,$headers)) {
            return true;
        } else {
          echo "faild";   

        }*/

 $mail = wp_mail($to,$subject,$message,$headers);
  $response  = array();
    if($mail){
    $response['success']  = "Successfull Request";
    echo json_encode($response);
    }
          else{
    $response['failed']  = "failed Request";
    echo json_encode($response);
          }
    exit;

    }

