function sunshine_local_checkout_validation()
{
    global $sunshine;
    if (isset($_POST['shipping_method']) && $sunshine->options['local_zipcodes'] && SunshineUser::get_user_meta('shipping_method') != 'download' && $_POST['shipping_method'] == 'local') {
        $zipcodes = array_map('trim', explode(',', $sunshine->options['local_zipcodes']));
        if (!in_array(SunshineUser::get_user_meta('shipping_zip'), $zipcodes)) {
            $sunshine->add_error(sprintf(__('Cannot choose %s shipping, not within allowed area', 'sunshine'), strtolower($sunshine->options['local_name'])));
        }
    }
}
 public static function state_dropdown($country, $name = 'state', $selected = '')
 {
     global $sunshine;
     $states = array();
     if ($country == '') {
         $country = $sunshine->options['country'];
     }
     if (isset(SunshineCountries::$states[$country])) {
         $states = SunshineCountries::$states[$country];
     }
     if ($selected == '') {
         $selected = SunshineUser::get_user_meta($name);
     }
     if ($states) {
         echo '<select name="' . $name . '">';
         echo '<option value="">' . __('Select state', 'sunshine') . '</option>';
         foreach ($states as $code => $name) {
             echo '<option value="' . $code . '" ' . selected($selected, $code, 0) . '>' . $name . '</option>';
         }
         echo '</select>';
     } else {
         echo '<input type="text" name="' . $name . '" value="' . $selected . '" />';
     }
 }
function sunshine_checkout_payment_methods()
{
    global $sunshine;
    ?>
	<fieldset id="sunshine-payment-methods"<?php 
    echo $sunshine->cart->total == 0 && $sunshine->cart->credits == 0 ? ' style="display: none;"' : '';
    ?>
>
		<h2><?php 
    _e('Payment Methods', 'sunshine');
    ?>
</h2>
		<?php 
    if ($sunshine->cart->credits > 0) {
        ?>
			<div id="sunshine-payment-credit"><label><input type="checkbox" name="use_credits" value="1" <?php 
        checked($sunshine->cart->use_credits, 1);
        ?>
 />
				<?php 
        printf(__('Use my %s in credit', 'sunshine'), sunshine_money_format($sunshine->cart->credits, false));
        ?>
			</div>
		<?php 
    }
    ?>
			<ul id="sunshine-payment-method-options">
			<?php 
    $user_payment_method = SunshineUser::get_user_meta('payment_method');
    foreach (SunshinePaymentMethods::$payment_methods as $payment_method) {
        echo '<li id="sunshine-payment-method-' . $payment_method['key'] . '">
						<label><input type="radio" name="payment_method" value="' . $payment_method['key'] . '" ' . checked($payment_method['key'], $user_payment_method, 0) . ' /> ' . $payment_method['name'] . '</label>
						<div class="sunshine-payment-method-description">' . $payment_method['description'] . '</div>
						<div class="sunshine-payment-method-extra">';
        do_action('sunshine_payment_method_extra_' . $payment_method['key']);
        echo '</div>
				</li>';
    }
    ?>
			</ul>
			<?php 
    do_action('sunshine_checkout_payment_methods');
    echo '</fieldset>';
}
function sunshine_paypal_redirect()
{
    global $current_user, $sunshine;
    if (is_page($sunshine->options['page_checkout']) && isset($_GET['paypal_redirect']) && isset($_GET['order_id'])) {
        $order = get_post((int) $_GET['order_id']);
        if (!$order) {
            wp_die(__('ERROR, something went really wrong', 'sunshine') . ' (1)');
            exit;
        }
        $status = sunshine_get_order_status($order->ID);
        if ($status->slug != 'pending') {
            wp_die(__('ERROR, something went really wrong', 'sunshine') . ' (2)');
            exit;
        }
        $paypal_args = array();
        $paypal_args['custom'] = $order->ID;
        $paypal_url = $sunshine->options['paypal_test_mode'] ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr';
        ?>
	<html>
		<head>
			<title><?php 
        _e('Redirecting to PayPal', 'sunshine');
        ?>
...</title>
			<style type="text/css">
			body, html { margin: 0; padding: 50px; background: #FFF; }
			h1 { color: #000; text-align: center; font-family: Arial; font-size: 24px; }
			</style>
		</head>
		<body>
			<h1><?php 
        _e('Redirecting to PayPal', 'sunshine');
        ?>
...</h1>
			<form method="post" action="<?php 
        echo $paypal_url;
        ?>
" id="paypal" style="display: none;">

			<?php 
        // Cart info
        $order_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));
        $i = 1;
        foreach ($order_items as $item) {
            $name_key = 'item_name_' . $i;
            $quantity_key = 'quantity_' . $i;
            $amount_key = 'amount_' . $i;
            $product = get_post($item['product_id']);
            $cat = wp_get_post_terms($item['product_id'], 'sunshine-product-category');
            $name = apply_filters('sunshine_cart_item_category', isset($cat[0]->name) ? $cat[0]->name : '', $item) . ' - ' . apply_filters('sunshine_cart_item_name', $product->post_title, $item);
            if ($item['image_id'] > 0) {
                $image = get_post($item['image_id']);
                $name = $image->post_title . ' - ' . $name;
            }
            $paypal_args[$name_key] = $name;
            $paypal_args[$quantity_key] = $item['qty'];
            $paypal_args[$amount_key] = number_format($item['price'], 2);
            $i++;
        }
        if ($sunshine->cart->shipping_method['cost'] > 0) {
            $paypal_args['item_name_' . $i] = sprintf(__('Shipping via %s', 'sunshine'), $sunshine->cart->shipping_method['title']);
            $paypal_args['quantity_' . $i] = 1;
            $paypal_args['amount_' . $i] = number_format($sunshine->cart->shipping_method['cost'], 2);
        }
        $paypal_args['tax_cart'] = number_format($sunshine->cart->tax, 2);
        $discount_total = 0;
        if ($sunshine->cart->discount_total) {
            $discount_total = $sunshine->cart->discount_total;
        }
        if ($sunshine->cart->useable_credits) {
            $discount_total += $sunshine->cart->useable_credits;
        }
        $paypal_args['discount_amount_cart'] = number_format($discount_total, 2);
        /*
        $paypal_args['item_name_1'] = __( 'Order from ','sunshine' ).get_bloginfo( 'name' );
        $paypal_args['quantity_1'] = 1;
        $paypal_args['amount_1'] = number_format( $sunshine->cart->total, 2 );
        */
        // Business Info
        $paypal_args['business'] = $sunshine->options['paypal_email'];
        $paypal_args['cmd'] = '_cart';
        $paypal_args['upload'] = '1';
        $paypal_args['charset'] = 'utf-8';
        if ($sunshine->options['page_style']) {
            $paypal_args['page_style'] = $sunshine->options['page_style'];
        }
        $paypal_args['currency_code'] = $sunshine->options['currency'];
        $paypal_args['return'] = add_query_arg(array('paypal_complete' => '1'), get_permalink($order->ID));
        $paypal_args['cancel_return'] = wp_nonce_url(add_query_arg('order_id', $order->ID, sunshine_url('checkout')), 'paypal_cancel', 'paypal_cancel');
        $paypal_args['notify_url'] = trailingslashit(get_bloginfo('url')) . '?sunshine_paypal_ipn=paypal_standard_ipn';
        if (isset($order_data['shipping_method']) && ($order_data['shipping_method'] == 'pickup' || $order_data['shipping_method'] == 'download')) {
            // Don't need any shipping info, so don't pass anything
            $paypal_args['no_shipping'] = 1;
        } else {
            // Need shipping information
            $paypal_args['no_shipping'] = 2;
            $paypal_args['address_override'] = 1;
            // Send what we got
            $paypal_args['address1'] = SunshineUser::get_user_meta('shipping_address');
            $paypal_args['address2'] = SunshineUser::get_user_meta('shipping_address2');
            $paypal_args['city'] = SunshineUser::get_user_meta('shipping_city');
            $paypal_args['state'] = SunshineUser::get_user_meta('shipping_state');
            $paypal_args['zip'] = SunshineUser::get_user_meta('shipping_zip');
            $paypal_args['country'] = SunshineUser::get_user_meta('shipping_country');
        }
        // Prefill user info
        $paypal_args['first_name'] = SunshineUser::get_user_meta('first_name');
        $paypal_args['last_name'] = SunshineUser::get_user_meta('last_name');
        $paypal_args['email'] = SunshineUser::get_user_meta('email');
        $phone = preg_replace("/[^0-9,.]/", "", SunshineUser::get_user_meta('phone'));
        $paypal_args['night_phone_a'] = substr($phone, 0, 3);
        $paypal_args['night_phone_b'] = substr($phone, 3, 3);
        $paypal_args['night_phone_c'] = substr($phone, 6, 4);
        $paypal_args = apply_filters('sunshine_paypal_args', $paypal_args);
        foreach ($paypal_args as $key => $value) {
            $paypal_args_array[] = '<input type="hidden" name="' . esc_attr($key) . '" value="' . esc_attr($value) . '" />';
        }
        echo implode("\r\n", $paypal_args_array);
        ?>

			<input type="submit" value="<?php 
        _e('Submit payment via PayPal', 'sunshine');
        ?>
" style="border: none; background: #FFF; color: #FFF; box-shadow: none; text-shadow: none;" />
		</form>
		<script>
			document.getElementById("paypal").submit();
		</script>
		</body>
		</html>
<?php 
        die;
    }
}
function sunshine_add_favorite($image_id)
{
    $image_id = intval($image_id);
    $favorites = SunshineUser::get_user_meta('favorite', false);
    if (in_array($image_id, $favorites)) {
        return;
    }
    SunshineUser::add_user_meta('favorite', $image_id, false);
    $favorite_count = get_post_meta($image_id, 'sunshine_favorite_count', true);
    $favorite_count++;
    update_post_meta($image_id, 'sunshine_favorite_count', $favorite_count);
    do_action('sunshine_add_favorite', $image_id);
}
 function toggle_use_credit()
 {
     global $current_user;
     if (SunshineUser::get_user_meta('use_credits')) {
         SunshineUser::update_user_meta('use_credits', '0');
         return '0';
     } else {
         SunshineUser::update_user_meta('use_credits', '1');
         return '1';
     }
 }
<div id="sunshine" class="sunshine-clearfix <?php 
sunshine_classes();
?>
">

	<?php 
do_action('sunshine_before_content');
?>
	
	<div id="sunshine-main">

		<?php 
$credits = SunshineUser::get_user_meta('credits');
if ($credits > 0) {
    ?>
			<h2><?php 
    _e('Credits', 'sunshine');
    ?>
</h2>
			<p>
				<?php 
    printf(__('You have %s in credit', 'sunshine'), sunshine_money_format($credits, false));
    ?>
			</p>
		<?php 
}
?>

		<div id="sunshine-account-orders">
			<h2><?php 
_e('Orders', 'sunshine');