function sunshine_reports_page()
{
    global $sunshine;
    ?>
	<div class="wrap sunshine">
		<h2><?php 
    _e('Reports', 'sunshine');
    ?>
</h2>
		<h3>Sales Taxes Collected</h3>
		<?php 
    $tax_years = array();
    $args = array('post_type' => 'sunshine-order', 'nopaging' => true, 'tax_query' => array(array('taxonomy' => 'sunshine-order-status', 'field' => 'slug', 'terms' => array('shipped'))));
    $orders = get_posts($args);
    foreach ($orders as $order) {
        $order_data = unserialize(get_post_meta($order->ID, '_sunshine_order_data', true));
        $year = date('Y', strtotime($order->post_date));
        $tax_years[$year] += $order_data['tax'];
    }
    if (!empty($tax_years)) {
        foreach ($tax_years as $tax_year => $tax_amount) {
            echo '<p><strong>' . $tax_year . '</strong>: ' . sunshine_money_format($tax_amount, false) . '</p>';
        }
    } else {
        _e('No taxes have been collected thus far', 'sunshine');
    }
    ?>
	</div>
<?php 
}
function sunshine_checkout_order_review()
{
    global $sunshine;
    ?>
	<div id="sunshine-checkout-order-review">
		<h2><?php 
    _e('Order Summary', 'sunshine');
    ?>
</h2>
		<p><a href="#sunshine-order-review-cart" id="sunshine-order-review-cart-link"><?php 
    _e('View items in cart', 'sunshine');
    ?>
</a></p>
		<div id="sunshine-order-review-cart" style="display: none;">
			<table id="sunshine-cart-items">
			<tr>
				<th class="sunshine-cart-image"><?php 
    _e('Image', 'sunshine');
    ?>
</th>
				<th class="sunshine-cart-name"><?php 
    _e('Product', 'sunshine');
    ?>
</th>
				<th class="sunshine-cart-qty"><?php 
    _e('Qty', 'sunshine');
    ?>
</th>
				<th class="sunshine-cart-price"><?php 
    _e('Item Price', 'sunshine');
    ?>
</th>
				<th class="sunshine-cart-total"><?php 
    _e('Item Total', 'sunshine');
    ?>
</th>
			</tr>
			<?php 
    $i = 1;
    $tabindex = 0;
    foreach (sunshine_cart_items() as $item) {
        $tabindex++;
        ?>
				<tr class="sunshine-cart-item <?php 
        sunshine_product_class($item['product_id']);
        ?>
">
					<td class="sunshine-cart-item-image" data-label="<?php 
        _e('Image', 'sunshine');
        ?>
">
						<?php 
        $thumb = wp_get_attachment_image_src($item['image_id'], 'sunshine-thumbnail');
        $image_html = '<a href="' . get_permalink($item['image_id']) . '"><img src="' . $thumb[0] . '" alt="" class="sunshine-image-thumb" /></a>';
        echo apply_filters('sunshine_cart_image_html', $image_html, $item, $thumb);
        ?>
					</td>
					<td class="sunshine-cart-item-name" data-label="<?php 
        _e('Product', 'sunshine');
        ?>
">
						<?php 
        $product = get_post($item['product_id']);
        $cat = wp_get_post_terms($item['product_id'], 'sunshine-product-category');
        ?>
						<h3><span class="sunshine-item-cat"><?php 
        echo apply_filters('sunshine_cart_item_category', isset($cat[0]->name) ? $cat[0]->name : '', $item);
        ?>
</span> - <span class="sunshine-item-name"><?php 
        echo apply_filters('sunshine_cart_item_name', $product->post_title, $item);
        ?>
</span></h3>
						<div class="sunshine-item-comments"><?php 
        echo apply_filters('sunshine_cart_item_comments', $item['comments'], $item);
        ?>
</div>
					</td>
					<td class="sunshine-cart-item-qty" data-label="<?php 
        _e('Qty', 'sunshine');
        ?>
">
						<?php 
        echo $item['qty'];
        ?>
					</td>
					<td class="sunshine-cart-item-price" data-label="<?php 
        _e('Price', 'sunshine');
        ?>
">
						<?php 
        sunshine_money_format($item['price']);
        ?>
					</td>
					<td class="sunshine-cart-item-total" data-label="<?php 
        _e('Total', 'sunshine');
        ?>
">
						<?php 
        sunshine_money_format($item['total']);
        ?>
					</td>
				</tr>

			<?php 
        $i++;
    }
    ?>
			</table>
		</div>
		<script>
		jQuery(document).ready(function($){
			$('#sunshine-order-review-cart-link').click(function(){
				$('#sunshine-order-review-cart').toggle();
				return false;
			});
		});
		</script>
		<table id="sunshine-checkout-review-totals">
		<tr class="sunshine-subtotal">
			<th><?php 
    _e('Item(s) total', 'sunshine');
    ?>
</th>
			<td><?php 
    sunshine_subtotal();
    ?>
</td>
		</tr>
		<?php 
    if ($sunshine->options['tax_location'] && $sunshine->options['tax_rate']) {
        ?>
		<tr class="sunshine-tax">
			<th><?php 
        _e('Tax', 'sunshine');
        ?>
</th>
			<td><?php 
        sunshine_tax_total();
        ?>
</td>
		</tr>
		<?php 
    }
    ?>
		<tr class="sunshine-shipping">
			<th><?php 
    _e('Shipping', 'sunshine');
    ?>
</th>
			<td><?php 
    sunshine_shipping_method();
    ?>
</td>
		</tr>
		<?php 
    if ($sunshine->cart->discount_total > 0) {
        ?>
		<tr class="sunshine-discount">
			<th><?php 
        _e('Discounts', 'sunshine');
        ?>
</th>
			<td><?php 
        sunshine_discount_total();
        ?>
</td>
		</tr>
		<?php 
    }
    ?>
		<tr class="sunshine-credits"<?php 
    if (!$sunshine->cart->use_credits) {
        echo 'style="display: none;"';
    }
    ?>
>
			<th><?php 
    _e('Credits', 'sunshine');
    ?>
</th>
			<td><?php 
    sunshine_usable_credits();
    ?>
</td>
		</tr>
		<tr class="sunshine-total">
			<th><?php 
    _e('Order Total', 'sunshine');
    ?>
</th>
			<td><?php 
    sunshine_total();
    ?>
</td>
		</tr>
		</table>
	</div>
<?php 
}
function sunshine_paypal_order_meta_box_inner()
{
    global $post;
    $txn_id = get_post_meta($post->ID, 'txn_id', true);
    $payment_fee = get_post_meta($post->ID, 'payment_fee', true);
    $ipn_track_id = get_post_meta($post->ID, 'ipn_track_id', true);
    $verify_sign = get_post_meta($post->ID, 'verify_sign', true);
    $payer_id = get_post_meta($post->ID, 'payer_id', true);
    $mode = get_post_meta($post->ID, 'mode', true);
    $paypal_url = $mode == 'test' ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr';
    ?>
    <p><strong>PayPal Transaction ID</strong>: <a href="<?php 
    echo $paypal_url;
    ?>
?cmd=_view-a-trans&id=<?php 
    echo $txn_id;
    ?>
" target="_blank"><?php 
    echo $txn_id;
    ?>
</a></p>
    <p><strong>Transaction Fee</strong>: <?php 
    sunshine_money_format($payment_fee);
    ?>
</p>
	<?php 
}
</a>
			</td>
			<td class="sunshine-cart-item-price" data-label="<?php 
        _e('Price', 'sunshine');
        ?>
">
				<?php 
        sunshine_money_format($item['price']);
        ?>
			</td>
			<td class="sunshine-cart-item-total" data-label="<?php 
        _e('Total', 'sunshine');
        ?>
">
				<?php 
        sunshine_money_format($item['total']);
        ?>
				<input type="hidden" name="item[<?php 
        echo $i;
        ?>
][image_id]" value="<?php 
        echo $item['image_id'];
        ?>
" />
				<input type="hidden" name="item[<?php 
        echo $i;
        ?>
][product_id]" value="<?php 
        echo $item['product_id'];
        ?>
" />
function sunshine_checkout_use_credits()
{
    global $sunshine;
    $status = $sunshine->cart->toggle_use_credit();
    $sunshine->cart->set_cart();
    $return['status'] = $status;
    $return['credits'] = '-' . sunshine_money_format($sunshine->cart->useable_credits, false);
    $return['total'] = sunshine_money_format($sunshine->cart->total, false);
    if ($sunshine->cart->total == 0) {
        $return['free'] = 1;
    } else {
        $return['free'] = 0;
    }
    die(json_encode($return));
}
function sunshine_dashboard_widget_stats($post, $callback_args)
{
    echo '<ul id="sunshine-dashboard-widget-stats" class="sunshine-clearfix">';
    $args = array('post_type' => 'sunshine-gallery', 'nopaging' => true);
    $galleries = get_posts($args);
    if (is_array($galleries)) {
        $gallery_total = count($galleries);
        $image_total = 0;
        foreach ($galleries as $gallery) {
            $images = get_children(array('post_parent' => $gallery->ID, 'post_type' => 'attachment'));
            $image_total += count($images);
        }
    }
    if ($gallery_total) {
        echo '<li><span class="data">' . $gallery_total . '</span><a href="edit.php?post_type=sunshine-gallery">' . __('Galleries', 'sunshine') . '</a></li>';
    }
    if ($image_total) {
        echo '<li><span class="data">' . $image_total . '</span>' . __('Images', 'sunshine') . '</li>';
    }
    $args = array('post_type' => 'sunshine-product', 'nopaging' => true);
    $products = get_posts($args);
    if (is_array($products)) {
        $product_total = count($products);
    }
    if ($gallery_total) {
        echo '<li><span class="data">' . $product_total . '</span><a href="edit.php?post_type=sunshine-product">' . __('Products', 'sunshine') . '</a></li>';
    }
    $args = array('post_type' => 'sunshine-order', 'nopaging' => true, 'tax_query' => array(array('taxonomy' => 'sunshine-order-status', 'field' => 'slug', 'terms' => array('new', 'processing', 'shipped'))));
    $orders = get_posts($args);
    if (is_array($orders)) {
        $order_total = 0;
        foreach ($orders as $order) {
            $order_data = unserialize(get_post_meta($order->ID, '_sunshine_order_data', true));
            $order_total += $order_data['total'];
        }
    }
    if ($order_total) {
        echo '<li><span class="data">' . sunshine_money_format($order_total, false) . '</span><a href="edit.php?post_type=sunshine-order">' . __('Orders', 'sunshine') . '</a></li>';
    }
    echo '</ol>';
}
function sunshine_admin_user_cart($user)
{
    if (current_user_can('sunshine_manage_options')) {
        $items = SunshineUser::get_user_meta_by_id($user->ID, 'cart', false);
        $orders = get_posts('post_type=sunshine-order&meta_key=_sunshine_customer_id&meta_value=' . $user->ID . '&nopaging=1');
        ?>
		<h3><?php 
        _e('Orders', 'sunshine');
        ?>
</h3>
		<?php 
        if ($orders) {
            echo '<ul>';
            foreach ($orders as $order) {
                $order_data = unserialize(get_post_meta($order->ID, '_sunshine_order_data', true));
                $total = sunshine_money_format($order_data['total'], false);
                echo '<li><a href="post.php?post=124&action=edit">' . $order->post_title . '</a>, ' . date(get_option('date_format'), strtotime($order->post_date)) . ' &mdash; ' . $total . '</li>';
            }
        } else {
            echo '<li><em>' . __('User has no orders yet', 'sunshine') . '</em></li>';
        }
        ?>
		<h3><?php 
        _e('Address Information', 'sunshine');
        ?>
</h3>
		<table class="form-table">
	 	<tr>
	 		<th><?php 
        _e('Billing Information', 'sunshine');
        ?>
</th>
	 		<td>
				<?php 
        $address = SunshineUser::get_user_meta_by_id($user->ID, 'address');
        $address2 = SunshineUser::get_user_meta_by_id($user->ID, 'address2');
        $city = SunshineUser::get_user_meta_by_id($user->ID, 'city');
        $state = SunshineUser::get_user_meta_by_id($user->ID, 'state');
        $zip = SunshineUser::get_user_meta_by_id($user->ID, 'zip');
        $country = SunshineUser::get_user_meta_by_id($user->ID, 'country');
        if ($address) {
            echo $address . '<br />';
            if ($address2) {
                echo $address2 . '<br />';
            }
            echo $city . ', ' . $state . ' ' . $zip . '<br />' . $country;
        } else {
            echo '<em>' . __('No current billing address', 'sunshine') . '</em>';
        }
        ?>
			</td>
	 	</tr>
	 	<tr>
	 		<th><?php 
        _e('Shipping Information', 'sunshine');
        ?>
</th>
	 		<td>
				<?php 
        $address = SunshineUser::get_user_meta_by_id($user->ID, 'shipping_address');
        $address2 = SunshineUser::get_user_meta_by_id($user->ID, 'shipping_address2');
        $city = SunshineUser::get_user_meta_by_id($user->ID, 'shipping_city');
        $state = SunshineUser::get_user_meta_by_id($user->ID, 'shipping_state');
        $zip = SunshineUser::get_user_meta_by_id($user->ID, 'shipping_zip');
        $country = SunshineUser::get_user_meta_by_id($user->ID, 'shipping_country');
        if ($address) {
            echo $address . '<br />';
            if ($address2) {
                echo $address2 . '<br />';
            }
            echo $city . ', ' . $state . ' ' . $zip . '<br />' . $country;
        } else {
            echo '<em>' . __('No current shipping address', 'sunshine') . '</em>';
        }
        ?>
			</td>
	 	</tr>
	 	</table>
	 	<h3 id="sunshine-credits"><?php 
        _e('Sunshine Gallery Credits for Purchases', 'sunshine');
        ?>
</h3>
		<table class="form-table">
	 	<tr>
	 		<th><label for="sunshine_credits"><?php 
        _e('Credits', 'sunshine');
        ?>
</label></th>
	 		<td>
				<?php 
        $currency_symbol = sunshine_currency_symbol();
        $currency_symbol_format = sunshine_currency_symbol_format();
        $text_field = '<input type="text" name="sunshine_credits" id="sunshine_credits" value="' . esc_attr(SunshineUser::get_user_meta_by_id($user->ID, 'credits')) . '" />';
        echo sprintf($currency_symbol_format, $currency_symbol, $text_field);
        ?>
			</td>
	 	</tr>
	 	</table>
	 	<h3 id="sunshine-cart"><?php 
        _e('Sunshine Items in Cart', 'sunshine');
        ?>
</h3>
		<?php 
        if ($items) {
            ?>
			<table id="sunshine-cart-items" width="100%">
			<tr>
				<th class="image"><?php 
            _e('Image', 'sunshine');
            ?>
</th>
				<th class="name"><?php 
            _e('Product', 'sunshine');
            ?>
</th>
				<th class="qty"><?php 
            _e('Quantity', 'sunshine');
            ?>
</th>
				<th class="price"><?php 
            _e('Item Price', 'sunshine');
            ?>
</th>
			</tr>
			<?php 
            foreach ($items as $item) {
                ?>
				<tr class="item">
					<td class="image">
						<?php 
                $thumb = wp_get_attachment_image_src($item['image_id'], 'thumbnail');
                $image_html = '<a href="' . get_permalink($item['image_id']) . '"><img src="' . $thumb[0] . '" alt="" class="image-thumb" /></a>';
                echo apply_filters('sunshine_cart_image_html', $image_html, $item, $thumb);
                ?>
					</td>
					<td class="name">
						<?php 
                $product = get_post($item['product_id']);
                $cat = wp_get_post_terms($item['product_id'], 'sunshine-product-category');
                ?>
						<strong><span class="sunshine-item-cat"><?php 
                echo apply_filters('sunshine_cart_item_category', isset($cat[0]->name) ? $cat[0]->name : '', $item);
                ?>
</span> - <span class="sunshine-item-name"><?php 
                echo apply_filters('sunshine_cart_item_name', $product->post_title, $item);
                ?>
</span></strong><br />
						<div class="sunshine-item-comments"><?php 
                echo apply_filters('sunshine_cart_item_comments', $item['comments'], $item);
                ?>
</div>
					</td>
					<td class="qty">
						<?php 
                echo $item['qty'];
                ?>
					</td>
					<td class="price">
						<?php 
                sunshine_money_format($item['price']);
                ?>
					</td>
				</tr>
			<?php 
            }
            ?>
			</table>
		<?php 
        } else {
            ?>
			<p><?php 
            _e('No items in cart', 'sunshine');
            ?>
</p>
		<?php 
        }
        ?>
	<?php 
    }
}
 public function show_item_price($product_id, $qty)
 {
     $price = $this->get_product_price($product_id, false);
     if (is_numeric($price)) {
         $price = $price * $qty;
     }
     sunshine_money_format($price);
 }
					<td><a href="<?php 
        the_permalink();
        ?>
"><?php 
        _e('Order', 'sunshine');
        ?>
 #<?php 
        the_ID();
        ?>
</a></td>
					<td><?php 
        the_time('M j, Y');
        ?>
</td>
					<td><?php 
        sunshine_money_format($order_data['total']);
        ?>
</td>
					<td>
						<?php 
        $order_status = wp_get_object_terms($post->ID, 'sunshine-order-status');
        echo $order_status[0]->name;
        ?>
			
					</td>
					</tr>
				<?php 
    }
    wp_reset_postdata();
    ?>
				</table>
function sunshine_product_columns_content($column, $post_id)
{
    global $post;
    switch ($column) {
        case 'category':
            $package = get_post_meta($post_id, 'sunshine_product_package', true);
            if ($package) {
                _e('Package', 'sunshine');
                break;
            }
            $terms = get_the_terms($post_id, 'sunshine-product-category');
            if (!empty($terms)) {
                $out = array();
                foreach ($terms as $term) {
                    $out[] = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('post_type' => $post->post_type, 'sunshine-product-category' => $term->slug), 'edit.php')), esc_html(sanitize_term_field('name', $term->name, $term->term_id, 'genre', 'display')));
                }
                echo join(', ', $out);
            } else {
                _e('No categories');
            }
            break;
        case 'price':
            $price_levels = get_terms('sunshine-product-price-level', array('hide_empty' => false));
            foreach ($price_levels as $price_level) {
                $price = get_post_meta($post->ID, 'sunshine_product_price_' . $price_level->term_id, true);
                echo $price_level->name . ': ';
                if ($price == '') {
                    echo '&mdash;';
                } else {
                    sunshine_money_format($price);
                    echo '<input type="hidden" name="sunshine_product_price_' . $price_level->term_id . '" data-price-level="' . $price_level->term_id . '" value="' . $price . '" />';
                }
                echo '<br />';
            }
            echo '<input type="hidden" name="sunshine_product_taxable_value" value="' . get_post_meta($post_id, 'sunshine_product_taxable', true) . '" />';
            echo '<input type="hidden" name="sunshine_product_shipping_value" value="' . get_post_meta($post_id, 'sunshine_product_shipping', true) . '" />';
            break;
        default:
            break;
    }
}
function sunshine_gallery_orders_meta_box()
{
    $gallery_id = $_GET['post'];
    $args = array('post_type' => 'sunshine-order', 'nopaging' => true);
    $orders = get_posts($args);
    $gallery_orders = array();
    foreach ($orders as $order) {
        $order_items = maybe_unserialize(get_post_meta($order->ID, '_sunshine_order_items', true));
        foreach ($order_items as $item) {
            if ($item['image_id']) {
                $image = get_post($item['image_id']);
                if ($image->post_parent == $gallery_id) {
                    $gallery_orders[] = $order->ID;
                    continue 2;
                }
            }
        }
    }
    if (!empty($gallery_orders)) {
        ?>
	<table>
	<tr>
		<th><?php 
        _e('Order #', 'sunshine');
        ?>
</th>
		<th><?php 
        _e('Customer', 'sunshine');
        ?>
</th>
		<th><?php 
        _e('Status', 'sunshine');
        ?>
</th>
		<th><?php 
        _e('Total', 'sunshine');
        ?>
</th>
	</tr>
	<?php 
        foreach ($gallery_orders as $order_id) {
            $customer_id = get_post_meta($order_id, '_sunshine_customer_id', true);
            if ($customer_id) {
                $customer = get_user_by('id', $customer_id);
            }
            $current_status = get_the_terms($order_id, 'sunshine-order-status');
            $status = array_values($current_status);
            $order_data = unserialize(get_post_meta($order_id, '_sunshine_order_data', true));
            ?>
			<tr>
				<td><a href="post.php?post=<?php 
            echo $order_id;
            ?>
&action=edit"><?php 
            echo sprintf(__('Order #%s', 'sunshine'), $order_id);
            ?>
</a></td>
				<td>
					<?php 
            if ($customer_id) {
                ?>
						<a href="user-edit.php?user_id=<?php 
                echo $customer_id;
                ?>
"><?php 
                echo $customer->display_name;
                ?>
</a>
					<?php 
            } else {
                echo __('Guest', 'sunshine') . ' &mdash; ' . $order_data['first_name'] . ' ' . $order_data['last_name'];
            }
            ?>
				</td>
				<td><?php 
            echo $status[0]->name;
            ?>
</td>
				<td><?php 
            sunshine_money_format($order_data['total']);
            ?>
			</tr>
		<?php 
        }
        ?>
	</table>
	<?php 
    }
}
 public static function notify($order_id)
 {
     global $sunshine;
     $data = maybe_unserialize(get_post_meta($order_id, '_sunshine_order_data', true));
     $order_items = maybe_unserialize(get_post_meta($order_id, '_sunshine_order_items', true));
     $discount_items = maybe_unserialize(get_post_meta($order_id, '_sunshine_order_discounts', true));
     // Send confirmation email
     $th_style = 'padding: 0 20px 5px 0; border-bottom: 1px solid #CCC; text-align: left; font-size: 10px; color: #999; text-decoration: none;';
     $td_style = 'padding: 5px 20px 5px 0; text-align: left; font-size: 12px;';
     $items_html = '';
     $items_html = apply_filters('sunshine_before_order_receipt_items', $items_html, $order_id, $order_items);
     $items_html .= '<div class="order-items"><h3 style="font-size: 14px;">' . __('Cart Items', 'sunshine') . '</h3>';
     $items_html .= ' <table border="0" cellspacing="0" cellpadding="0" width="100%">';
     $items_html .= ' <tr><th style="' . $th_style . '">' . __('Image', 'sunshine') . '</th><th style="' . $th_style . '">' . __('Name', 'sunshine') . '</th><th style="' . $th_style . '">' . __('Quantity', 'sunshine') . '</th><th style="' . $th_style . '">' . __('Cost', 'sunshine') . '</th></tr>';
     foreach ($order_items as $key => $order_item) {
         $items_html .= ' <tr>';
         $thumb = wp_get_attachment_image_src($order_item['image_id'], 'sunshine-thumbnail');
         $image_html = '<img src="' . $thumb[0] . '" alt="" width="75" />';
         $items_html .= ' <td style="' . $td_style . '">' . apply_filters('sunshine_order_image_html', $image_html, $order_item, $thumb) . '</td>';
         $items_html .= ' <td style="' . $td_style . '">' . $order_item['product_name'] . '<br />' . apply_filters('sunshine_order_line_item_comments', $order_item['comments'], $order_id, $order_item) . '</td>';
         $items_html .= ' <td style="' . $td_style . '">' . $order_item['qty'] . '</td>';
         $items_html .= ' <td style="' . $td_style . '">' . sunshine_money_format($order_item['total'], false) . '</td>';
         $items_html .= ' </tr>';
     }
     $td_style .= ' font-weight: bold;';
     $th_style = 'padding: 0 20px 5px 0; text-align: left; font-size: 12px;';
     $items_html .= ' <tr><td colspan="3" style="' . $td_style . ' text-align: right; border-top: 2px solid #CCC;">' . __('Subtotal', 'sunshine') . '</td><td style="' . $td_style . ' border-top: 2px solid #CCC;">' . sunshine_money_format($data['subtotal'], false) . '</td></tr>';
     $items_html .= ' <tr><td colspan="3" style="' . $td_style . ' text-align: right;">' . __('Shipping', 'sunshine') . ' (' . sunshine_get_shipping_method_name($data['shipping_method']) . ')</td><td style="' . $td_style . '">' . sunshine_money_format($data['shipping_cost'], false) . '</td></tr>';
     if ($sunshine->options['tax_location'] && $sunshine->options['tax_rate']) {
         $items_html .= ' <tr><td colspan="3" style="' . $td_style . ' text-align: right;">' . __('Tax', 'sunshine') . '</td><td style="' . $td_style . '">' . sunshine_money_format($data['tax'], false) . '</td></tr>';
     }
     if ($data['discount_total'] > 0) {
         $items_html .= ' <tr><td colspan="3" style="' . $td_style . ' text-align: right;">' . __('Discounts', 'sunshine') . '</td><td style="' . $td_style . '">' . sunshine_money_format($data['discount_total'], false) . '</td></tr>';
     }
     if ($data['credits']) {
         $items_html .= ' <tr><td colspan="3" style="' . $td_style . ' text-align: right;">' . __('Credits', 'sunshine') . '</td><td style="' . $td_style . '">-' . sunshine_money_format($data['credits'], false) . '</td></tr>';
     }
     $items_html .= ' <tr><td colspan="3" style="' . $td_style . ' text-align: right; font-size: 16px;">' . __('Total', 'sunshine') . '</td><td style="' . $td_style . ' font-size: 16px;">' . sunshine_money_format($data['total'], false) . '</td></tr>';
     $items_html .= ' </table></div>';
     $customer_info = '<br /><br /><table border="0" cellspacing="0" cellpadding="0"><tr>';
     if ($data['country']) {
         $customer_info .= '<td class="billing-address" valign="top"><h3 style="font-size: 14px;">' . __('Billing Info', 'sunshine') . '</h3><p>';
         $customer_info .= $data['first_name'] . ' ' . $data['last_name'] . '<br>';
         $customer_info .= $data['address'];
         if ($data['address2']) {
             $customer_info .= '<br>' . $data['address2'];
         }
         $customer_info .= '<br>' . $data['city'] . ', ' . $data['state'] . ' ' . $data['zip'];
         if ($data['country']) {
             $customer_info .= '<br>' . $data['country'];
         }
         if ($data['email']) {
             $customer_info .= '<br>' . $data['email'];
         }
         if ($data['phone']) {
             $customer_info .= '<br>' . $data['phone'];
         }
         $customer_info .= '</p></td>';
     }
     if ($data['shipping_country']) {
         $customer_info .= '<td class="shipping-address" valign="top"><h3 style="font-size: 14px;">' . __('Shipping Info', 'sunshine') . '</h3><p>';
         $customer_info .= $data['shipping_first_name'] . ' ' . $data['shipping_last_name'] . '<br>';
         $customer_info .= $data['shipping_address'];
         if ($data['shipping_address2']) {
             $customer_info .= '<br>' . $data['shipping_address2'];
         }
         $customer_info .= '<br>' . $data['shipping_city'] . ', ' . $data['shipping_state'] . ' ' . $data['shipping_zip'];
         if ($data['shipping_country']) {
             $customer_info .= '<br>' . $data['shipping_country'];
         }
         $customer_info .= '</p></td>';
     }
     $customer_info .= '</tr></table>';
     $search = array('[message]', '[items]', '[customer_info]', '[order_id]', '[order_url]', '[first_name]', '[last_name]');
     $replace = array(nl2br($sunshine->options['email_receipt']), $items_html, $customer_info, $order_id, get_permalink($order_id), $data['first_name'], $data['last_name']);
     $mail_result = SunshineEmail::send_email('receipt', $data['email'], $sunshine->options['email_subject_order_receipt'], $sunshine->options['email_subject_order_receipt'], $search, $replace, $data);
     if ($sunshine->options['order_notifications']) {
         $admin_emails = explode(',', $sunshine->options['order_notifications']);
     } else {
         $admin_emails = array(get_bloginfo('admin_email'));
     }
     foreach ($admin_emails as $admin_email) {
         $mail_result = SunshineEmail::send_email('receipt_admin', trim($admin_email), sprintf(__('Order #%s placed on %s'), $order_id, get_option('blogname')), sprintf(__('<a href="%s">Order #%s</a> placed on %s'), admin_url('/post.php?post=' . $order_id . '&action=edit'), $order_id, get_option('blogname')), $search, $replace, $data);
     }
 }
function sunshine_invoice_display()
{
    if (!isset($_GET['page']) || $_GET['page'] != 'sunshine_invoice_display') {
        return;
    }
    if (!isset($_GET['order']) || !wp_verify_nonce($_GET['nonce'], 'sunshine_invoice')) {
        wp_die(__('Sorry, no order specified', 'sunshine'));
        exit;
    }
    $order_id = intval($_GET['order']);
    $order = get_post($order_id);
    $order_data = unserialize(get_post_meta($order_id, '_sunshine_order_data', true));
    $items = unserialize(get_post_meta($order_id, '_sunshine_order_items', true));
    ?>
<!DOCTYPE html>
<html>
<head>
	<title>Invoice for Order #<?php 
    echo $order_id;
    ?>
</title>
	<meta charset="UTF-8" />
	<style type="text/css">
		*
		{
			border: 0;
			box-sizing: content-box;
			color: inherit;
			font-family: inherit;
			font-size: inherit;
			font-style: inherit;
			font-weight: inherit;
			line-height: inherit;
			list-style: none;
			margin: 0;
			padding: 0;
			text-decoration: none;
			vertical-align: top;
		}

		/* content editable */

		/* heading */

		h1 { font: bold 100% sans-serif; letter-spacing: 0.5em; text-align: center; text-transform: uppercase; }

		/* table */

		table { font-size: 75%; table-layout: fixed; width: 100%; }
		th, td { border-bottom: 1px solid #DDD; padding: 0.5em; position: relative; text-align: left; }
		th { background: #EEE; }
		td { border-color: #DDD; }

		td td { border: none; }


		/* page */

		html { font: 16px/1 'Open Sans', sans-serif; overflow: auto; padding: 0.5in; }
		html { background: #999; cursor: default; }

		body { box-sizing: border-box; height: 11in; margin: 0 auto; /*overflow: hidden;*/ padding: 0.5in; width: 8.5in; }
		body { background: #FFF; border-radius: 1px; box-shadow: 0 0 1in -0.25in rgba(0, 0, 0, 0.5); }

		/* header */

		header { margin: 0 0 3em; }
		header:after { clear: both; content: ""; display: table; }

		header { text-align: center; margin: 0 0 25px 0; }
		header h1 { background: #000; border-radius: 0.25em; color: #FFF; margin: 0 0 1em; padding: 0.5em 0; }
		header img { margin: 0 auto; height: auto; width: auto; max-height: 75px; }

		/* article */

		article, article address, table.meta, table.inventory { margin: 0 0 3em; }
		article:after { clear: both; content: ""; display: table; }
		article h1 { clip: rect(0 0 0 0); position: absolute; }

		article address { float: left; font-weight: bold; }

		/* table meta & balance */

		table.meta, table.balance { float: right; width: 36%; }
		table.meta:after, table.balance:after { clear: both; content: ""; display: table; }

		/* table meta */

		table.meta th { width: 40%; }
		table.meta td { width: 60%; }

		/* table items */

		table.inventory { clear: both; width: 100%; }
		table.inventory th { font-weight: bold; text-align: center; }

		table.inventory td { padding: 20px 0; }
		table.inventory td td { padding: 5px 0; }
		table.inventory td:nth-child(1) { width: 26%; }
		table.inventory td:nth-child(2) { width: 38%; }
		table.inventory td:nth-child(3) { text-align: right; width: 12%; }
		table.inventory td:nth-child(4) { text-align: right; width: 12%; }
		table.inventory td:nth-child(5) { text-align: right; width: 12%; }

		table.inventory td img { max-width: 100px; height: auto; }
		table.inventory td td img { max-width: 40px; height: auto; }
		/* table balance */

		table.balance th, table.balance td { width: 50%; white-space: nowrap;  }
		table.balance td { text-align: right;}

		/* aside */

		aside h1 { border: none; border-width: 0 0 1px; margin: 0 0 1em; }
		aside h1 { border-color: #999; border-bottom-style: solid; }


		@media print {
			* { -webkit-print-color-adjust: exact; }
			html { background: none; padding: 0; }
			body { box-shadow: none; margin: 0; }
			span:empty { display: none; }
			.add, .cut { display: none; }
		}

		@page { margin: 0; }
	</style>
</head>
<body>

	<header>
		<?php 
    sunshine_logo();
    ?>
	</header>
	<article>
		<h1><?php 
    _e('Recipient', 'sunshine');
    ?>
</h1>
		<address>
			<p>
				<?php 
    echo $order_data['first_name'] . ' ' . $order_data['last_name'] . '<br />' . $order_data['address'];
    if ($order_data['address2']) {
        echo '<br />' . $order_data['address2'];
    }
    echo '<br />' . $order_data['city'] . ', ' . $order_data['state'] . ' ' . $order_data['zip'] . '<br />' . $order_data['country'] . '<br />' . $order_data['email'] . '<br />' . $order_data['phone'];
    ?>
			</p>
		</address>
		<table class="meta" cellspacing="0" cellpadding="0">
			<tr>
				<th><span><?php 
    _e('Order #', 'sunshine');
    ?>
</span></th>
				<td><span><?php 
    echo $order_id;
    ?>
</span></td>
			</tr>
			<tr>
				<th><span><?php 
    _e('Date', 'sunshine');
    ?>
</span></th>
				<td><span><?php 
    echo get_the_date(get_option('date_format'), $order_id);
    ?>
</span></td>
			</tr>
			<tr>
				<th><span><?php 
    _e('Order Total', 'sunshine');
    ?>
</span></th>
				<td><span><?php 
    sunshine_money_format($order_data['total']);
    ?>
</span></td>
			</tr>
		</table>
		<table class="inventory">
			<thead>
				<tr>
					<th><span><?php 
    _e('Image', 'sunshine');
    ?>
</span></th>
					<th><span><?php 
    _e('Product', 'sunshine');
    ?>
</span></th>
					<th><span><?php 
    _e('Quantity', 'sunshine');
    ?>
</span></th>
					<th><span><?php 
    _e('Price', 'sunshine');
    ?>
</span></th>
					<th><span><?php 
    _e('Item Total', 'sunshine');
    ?>
</span></th>
				</tr>
			</thead>
			<tbody>
				<?php 
    $i = 1;
    foreach ($items as $item) {
        ?>
					<tr class="item">
						<td class="image">
							<?php 
        if ($item['image_id'] > 0) {
            $image = get_post($item['image_id']);
            $gallery = get_post($image->post_parent);
            if ($thumb = wp_get_attachment_image_src($item['image_id'], 'sunshine-thumbnail')) {
                $image_html = '<img src="' . $thumb[0] . '" alt="' . $item['image_name'] . '" width="100" />';
            } else {
                $image_html = '<img src="http://placehold.it/100&text=Image+deleted" alt="Image has been deleted" />';
            }
        }
        echo apply_filters('sunshine_cart_image_html', $image_html, $item, $thumb);
        ?>
						</td>
						<td class="name">
							<strong><?php 
        echo $item['product_name'];
        ?>
</strong><br />
							<div class="comments"><?php 
        echo apply_filters('sunshine_cart_item_comments', $item['comments'], $item);
        ?>
</div>
						</td>
						<td class="qty">
							<?php 
        echo $item['qty'];
        ?>
						</td>
						<td class="price">
							<?php 
        sunshine_money_format($item['price']);
        ?>
						</td>
						<td class="total">
							<?php 
        sunshine_money_format($item['total']);
        ?>
						</td>
					</tr>

				<?php 
        $i++;
    }
    ?>
			</tbody>
		</table>
		<table class="balance">
			<tr class="subtotal totals">
				<th colspan="4" align="right"><?php 
    _e('Subtotal', 'sunshine');
    ?>
</th>
				<td><?php 
    sunshine_money_format($order_data['subtotal']);
    ?>
</td>
			</tr>
			<tr class="tax totals">
				<th colspan="4" align="right"><?php 
    _e('Tax', 'sunshine');
    ?>
</th>
				<td><?php 
    sunshine_money_format($order_data['tax']);
    ?>
</td>
			</tr>
			<tr class="shipping totals">
				<th colspan="4" align="right"><?php 
    _e('Shipping', 'sunshine');
    ?>
 (<?php 
    echo $order_data['shipping_method'];
    ?>
)</th>
				<td>
					<?php 
    sunshine_money_format($order_data['shipping_cost']);
    ?>
				</td>
			</tr>
			<tr class="discounts totals">
				<th colspan="4" align="right">
					<?php 
    _e('Discounts', 'sunshine');
    ?>
					<?php 
    if (!empty($order_data['discount_items'])) {
        $discount_names = array();
        foreach ($order_data['discount_items'] as $discount_item) {
            $discount_names[] = $discount_item->name;
        }
        echo '<br />(' . join(', ', $discount_names) . ')';
    }
    ?>
				</th>
				<td>-<?php 
    sunshine_money_format($order_data['discount_total']);
    ?>
</td>
			</tr>
			<?php 
    if ($order_data['credits'] > 0) {
        ?>
			<tr class="credits totals">
				<th colspan="4" align="right"><?php 
        _e('Credits', 'sunshine');
        ?>
</th>
				<td>-<?php 
        sunshine_money_format($order_data['credits']);
        ?>
</td>
			</tr>
			<?php 
    }
    ?>

			<tr class="total totals">
				<th colspan="4" align="right"><?php 
    _e('Total', 'sunshine');
    ?>
</th>
				<td><?php 
    sunshine_money_format($order_data['total']);
    ?>
</td>
			</tr>
			<tr class="payment-method totals">
				<th colspan="4" align="right"><?php 
    _e('Payment Method', 'sunshine');
    ?>
</th>
				<td><?php 
    echo $order_data['payment_method'];
    ?>
</td>
			</tr>
		</table>
	</article>
</body>
</html>

<?php 
    exit;
}