<?php
/**
 * WC Cart PDF template
 * 
 * @package wc-cart-pdf
 */

/**
 * Before template hook
 *
 * @since 1.0.4
 */

do_action( 'wc_cart_pdf_before_template' );

$logo = parse_url( get_option( 'wc_cart_pdf_logo', get_option( 'woocommerce_email_header_image' ) ), PHP_URL_PATH );
$logo = ! $logo ? '' : $_SERVER['DOCUMENT_ROOT'] . $logo;
?>
<div id="pdf_append" >
<?php $base_url=site_url();
     $pdf_logo="<img src='https://successforkidswithhearingloss.com/wp-content/themes/sfk/assets/images/logo.jpg' alt='defaultImage' />"; 

$path='/home/successforkids/public_html/wp-content/themes/sfk/assets/images/';
$filename='logo.jpg';?>

<?php  $todate=date("m/d/Y"); 
$ship='0';
$hand='0';
$hand_int='0';
$special_ship='0';
if ( 0 < WC()->cart->get_shipping_total() ){
    $ship=WC()->cart->get_shipping_total();
}
if(isset($_SESSION['handling']) && $_SESSION['handling']!='') {
    $hand=$_SESSION['handling'];
    $hand_int=$_SESSION['handling-int'];
}
if(isset($_SESSION['shipping-25-off']) && $_SESSION['shipping-25-off']!='') {
    $shipoff=$_SESSION['shipping-25-off'];
}
$shipoff_val=str_replace("$","",$shipoff);
$shippoff_val=(float)$shipoff_val;

$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;


if(isset($_SESSION['special-str']) && $_SESSION['special-str']!=''){

    $special_ship=$_SESSION['special-str'];
    $special_ship_val=str_replace("$","",$special_ship);
}

       
    


 printf( '<img src="%s" />', esc_url( $path.$filename  ) );
 echo '<center><h1>QUOTE</h1></center>'; 

 echo  '<div class="customer-details">
      <h2>Customer Details</h2>
      <table border="0"><tbody>
      <tr><td> <strong>DATE </strong></td><td><strong>:</strong> ' .$todate. '</td></tr> 
      <tr><td> <strong>NAME </strong></td><td><strong>:</strong> ' . $_SESSION['p_name']. '</td></tr> 
       <tr><td> <strong>EMAIL </strong></td><td><strong>:</strong> ' . $_SESSION['p_email']. '</td></tr> 
       <tr><td> <strong>LOCATION </strong></td><td><strong>:</strong> ' . $_SESSION['p_location']. '</td></tr> 
      <tr><td> <strong>COMAPANY </strong></td><td><strong>:</strong> ' . $_SESSION['p_company']. '</td></tr> 
       <tr><td> <strong>Full Mailing Address </strong></td><td><strong>:</strong> ' . $_SESSION['p_email2']. '</td></tr> 
       <tr><td> <strong>MESSAGE </strong></td><td><strong>:</strong> ' . $_SESSION['p_message']. '</td></tr> 

     
      </tbody> </table> </div>' ;
 /*global $quote_name,$quote_email;
echo $quote_name.'test';
echo $quote_email;*/
  ?>  

<h2>Product Details</h2>
</div>

<div id="template_header_image">
    <?php
        if ( file_exists( $logo ) ) {
            printf( '<p style="margin-top: 0; text-align: %s;"><img src="%s" style="width: %s;" alt="%s" /></p>',
                get_option( 'wc_cart_pdf_logo_alignment', 'center' ),
                esc_url( $logo ),
                get_option( 'wc_cart_pdf_logo_width' ) ? get_option( 'wc_cart_pdf_logo_width' ) . 'px' : 'auto',
                get_bloginfo( 'name', 'display' )
            );
        }
    ?>
</div>
<table class="shop_table shop_table_responsive cart woocommerce-cart-form__contents" cellspacing="0">
    <thead>
        <tr>
            <th class="product-thumbnail">&nbsp;</th>
            <th class="product-name"><?php esc_html_e( 'Product', 'woocommerce' ); ?></th>
            <th class="product-price"><?php esc_html_e( 'Price', 'woocommerce' ); ?></th>
            <th class="product-quantity"><?php esc_html_e( 'Quantity', 'woocommerce' ); ?></th>
            <th class="product-subtotal"><?php esc_html_e( 'Total', 'woocommerce' ); ?></th>
        </tr>
    </thead>
    <tbody>
        <?php
        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 );
                ?>
                <tr class="woocommerce-cart-form__cart-item <?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?>">

                    <td class="product-thumbnail">
                    <?php
                    if ( $_product->get_image_id() ) {
                        $image = wp_get_attachment_image_src( $_product->get_image_id() );

                        $image = parse_url( $image[0], PHP_URL_PATH );

                        $thumbnail = sprintf( '<img src="%s" />', esc_url( $_SERVER['DOCUMENT_ROOT'] . $image ) );

                    }

                    if ( ! $product_permalink ) {
                        echo wp_kses_post( $thumbnail );
                    } else {
                        printf( '<a href="%s">%s</a>', esc_url( $product_permalink ), wp_kses_post( $thumbnail ) );
                    }
                    ?>
                    </td>

                    <td class="product-name" data-title="<?php esc_attr_e( 'Product', 'woocommerce' ); ?>">
                    <?php
                    if ( ! $product_permalink ) {
                        echo wp_kses_post( apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key ) . '&nbsp;' );
                    } else {
                        echo 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 ) );
                    }

                    do_action( 'woocommerce_after_cart_item_name', $cart_item, $cart_item_key );

                    // Meta data.
                    echo wc_get_formatted_cart_item_data( $cart_item ); // PHPCS: XSS ok.

                    // Backorder notification.
                    if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) ) {
                        echo wp_kses_post( apply_filters( 'woocommerce_cart_item_backorder_notification', '<p class="backorder_notification">' . esc_html__( 'Available on backorder', 'woocommerce' ) . '</p>' ) );
                    }
                    ?>
                    </td>

                    <td class="product-price" data-title="<?php esc_attr_e( 'Price', 'woocommerce' ); ?>">
                        <?php 
                            echo apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key ); // PHPCS: XSS ok.
                        ?>
                    </td>

                    <td class="product-quantity" data-title="<?php esc_attr_e( 'Quantity', 'woocommerce' ); ?>">
                        <?php print esc_html( $cart_item['quantity'] ); ?>
                    </td>

                    <td class="product-subtotal" data-title="<?php esc_attr_e( 'Total', 'woocommerce' ); ?>">
                        <?php
                            echo apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key ); // PHPCS: XSS ok.
                        ?>
                    </td>
                </tr>
                <?php
            }
        }
        ?>

        <tr class="cart-subtotal">
            <th class="row-subtotal" colspan="4" style="text-align: right;"><?php _e( 'Subtotal', 'woocommerce' ); ?></th>
            <td class="row-subtotal" data-title="<?php esc_attr_e( 'Subtotal', 'woocommerce' ); ?>"><?php wc_cart_totals_subtotal_html(); 
       
      ?>     
            </td>
        </tr>
        <?php if($_SESSION['special-str']!=''){ ?>
        <tr class="shipping">
                <th class="row-subtotal" colspan="4" style="text-align: right;"><?php  _e( 'Special Shipping Fee', 'woocommerce' ); ?></th>
                <td class="row-subtotal" data-title="<?php esc_attr_e( 'Special Shipping', 'woocommerce' ); ?>"><?php echo "$".$special_ship_val; ?></td>
            </tr> <?php } ?>

        <?php  //if ( 0 < WC()->cart->get_shipping_total() ) : ?>
            <tr class="shipping">
                <th class="row-subtotal" colspan="4" style="text-align: right;"><?php if($_SESSION['handling']!=''){ _e( 'Shipping & Handling', 'woocommerce' ); } else {  _e( 'Shipping', 'woocommerce' ); } ?></th>
                <td class="row-subtotal" data-title="<?php esc_attr_e( 'Shipping & Handling', 'woocommerce' ); ?>"><?php echo "$".$ship_hand; ?></td>
            </tr>
        <?php //endif; ?>
       
     
<?php if($_SESSION['shipping-25-off']!=''){ ?>
             <tr class="shipping">
            <th class="row-subtotal" colspan="4" style="text-align: right;"><?php _e( 'Shipping 25% Off', 'woocommerce' ); ?></th>
                <td class="row-subtotal" data-title="<?php esc_attr_e( 'Shipping 25% Off', 'woocommerce' ); ?>"><?php echo "$".$shippoff_val; ?></td>
            </tr>
        <?php } //endif; ?>

           <!-- <?php if($_SESSION['handling']!='')
 { ?>
    <tr class="fee">
                <th class="row-subtotal" colspan="4" style="text-align: right;">Handling</th>
                <td class="row-subtotal"><?php  echo $_SESSION['handling']; ?></td>
                    
                </tr>
     
 <?php } ?> -->



       <?php foreach ( WC()->cart->get_fees() as $fee ) : ?>
            <tr class="fee">
                <th class="row-subtotal" colspan="4" style="text-align: right;"><?php echo esc_html( $fee->name ); ?></th>
                <td class="row-subtotal" data-title="<?php echo esc_attr( $fee->name ); ?>"><?php wc_cart_totals_fee_html( $fee ); ?>
        

                </td>
            </tr>
        <?php endforeach; ?>

        <?php 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' ) ) : ?>
                <?php foreach ( WC()->cart->get_tax_totals() as $code => $tax ) : ?>
                    <tr class="tax-rate tax-rate-<?php echo sanitize_title( $code ); ?>">
                        <th class="row-subtotal" colspan="4" style="text-align: right;"><?php echo esc_html( $tax->label ) . $estimated_text; ?></th>
                        <td class="row-subtotal" data-title="<?php echo esc_attr( $tax->label ); ?>"><?php echo wp_kses_post( $tax->formatted_amount ); ?></td>
                    </tr>
                <?php endforeach; ?>
            <?php else : ?>
                <tr class="tax-total">
                    <th class="row-subtotal" colspan="4" style="text-align: right;"><?php echo esc_html( WC()->countries->tax_or_vat() ) . $estimated_text; ?></th>
                    <td class="row-subtotal" data-title="<?php echo esc_attr( WC()->countries->tax_or_vat() ); ?>"><?php wc_cart_totals_taxes_total_html(); ?></td>
                </tr>
            <?php endif; ?>
        <?php endif; if('0'){  ?>
<tr class="fee">  <?php  $ssub_total = WC()->cart->get_cart_subtotal();
$taxes_totel=0;
$taxes_totel1=WC()->cart->get_taxes_total();
$taxes_totel = strip_tags($taxes_totel1);

                $sub_stotal_v =  strip_tags($ssub_total);

        $sub_stotal = preg_replace('/&.*?;/', '', $sub_stotal_v);
  
            //echo $sub_stotal."</br>";

       $sub_ship_total = $sub_stotal+$ship_hand+$taxes_totel;

        $grand_total=WC()->cart->get_total();
       $grand_total_v =  strip_tags($grand_total);

       $ggrand_total=preg_replace('/&.*?;/', '', $grand_total_v);
        $extra1_cost = $ggrand_total-$sub_ship_total;

       if($extra1_cost!=0){?>
            
<th class="row-subtotal" colspan="4" style="text-align: right;">Special Shipping Fee</th>

<td class="row-subtotal" data-title="Special Shipping Fee"><?php echo $extra1_cost; ?> </td>

        
       <?php  }
        


        ?></tr>
        <?php   } do_action( 'woocommerce_cart_totals_before_order_total' ); ?>

        <tr class="order-total">
            <th class="row-subtotal" colspan="4" style="text-align: right;"><?php _e( 'Total', 'woocommerce' ); ?></th>
            <td class="row-subtotal" data-title="<?php esc_attr_e( 'Total', 'woocommerce' ); ?>"><?php wc_cart_totals_order_total_html();  ?></td>
        </tr>


        <?php do_action( 'woocommerce_cart_totals_after_order_total' ); ?>


    </tbody>
</table>
<div id="template_footer">
    <?php //echo wpautop( wp_kses_post( wptexturize( apply_filters( 'woocommerce_email_footer_text', get_option( 'woocommerce_email_footer_text' ) ) ) ) ); ?>
    <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>
</div>

<?php
/**
 * After template hook
 *
 * @since 1.0.4
 */
do_action( 'wc_cart_pdf_after_template' );
