<?php

 




// CART EXTRA HOOKS
function hook_cart_checkoutsteps_top(){  do_action('hook_cart_checkoutsteps_top');  }	
function hook_cart_checkoutsteps_bottom(){  do_action('hook_cart_checkoutsteps_bottom');  }	



  
 
add_action('hook_admin_1_topnav_top', '_hook_admin_1_topnav_top');

function _hook_admin_1_topnav_top(){

$core_admin_values = get_option("core_admin_values");  

// ONLY SHOW IF FULL HTML LAYOUT IS SELECTED
if($core_admin_values['layout_header'] != 6){ return; }

$default = array(

"1" => array("t" => "SECURE ONLINE PAYMENTS", "d" => "" ),
"2" => array("t" => "MONEY BACK GUARANTEE", "d" => "100% money back guarantee." ),
"3" => array("t" => "FREE SHIPPING &amp; PRODUCT RETURN", "d" => "Free shipping on all orders" ),
);

// GET DATA
$st = $core_admin_values['shoptop']; 

ob_start();
?>


<div class="heading2">Header Text (opposite logo) </div>
  
  
<?php foreach($default as $key => $t){ ?>
<div class="form-row control-group row-fluid">
	<label class="control-label span4">Box <?php echo $key; ?></label>
    <div class="controls span7">
    <p>Title</p>
    <input name="admin_values[shoptop][<?php echo $key; ?>][t]"  type="text" value="<?php if(isset($st[$key]['t']) && strlen($st[$key]['t']) > 0){ echo stripslashes($st[$key]['t']); }else{ echo $t['t']; } ?>" class="row-fluid">
    <p>Description</p>
    <input name="admin_values[shoptop][<?php echo $key; ?>][d]"  type="text" value="<?php if(isset($st[$key]['d']) && strlen($st[$key]['d']) > 0){ echo stripslashes($st[$key]['d']); }else{ echo $t['d']; }  ?>" class="row-fluid">
      
    </div>                      
</div>
<?php } ?>

<?php
echo ob_get_clean(); 
}
 
 
function _hook_menu($c){ global $CORE, $CORE_CART;
return $c.$CORE_CART->_BASKET(0);   
}
add_action('hook_menu', '_hook_menu');

function _hook_menu_searchbox(){ 
return "";
}
add_action('hook_menu_searchbox', '_hook_menu_searchbox');



  
// start shoppig cart class
class shopping_cart extends white_label_themes {

	public $shop_field_types;
 
	function __construct(){
	
	$GLOBALS['shipping_amount_list'] = array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","20+");
 
		// ADMIN FUNCTIONS
		if(is_admin()){
			
			// NEW SETTINGS TAB		
			add_action('hook_admin_1_pagesetup', array($this, '_hook_admin_1_pagesetup'  ) ); 
			
			// ADD IN EXTRA TABS FOR SHIPPING AND TAX
			add_action('hook_admin_9_tabs', array($this, '_new_admin_tabs' ) );
			// TAX SETTING
			add_action('hook_admin_9_content','basic_tax_shipping'); 	
			 
			// HOOK INTO THE EDIT PAGE AND ADD-ON STORE FIELDS
			add_action('hook_fieldlist_0', array($this, '_store_fields' ) );
			add_action('hook_fieldlist_1', array($this, '_blankfields1' ) );
			add_action('hook_fieldlist_2', array($this, '_blankfields' ) );
		 
			// ADD ON  PAGE LINK
			add_action('hook_admin_1_tab1_subtab2_pagelist', array($this,'_updatepagelist' ));
			
			add_action('hook_admin_2_homeedit', array($this, '_hook_admin_2_homeedit' ), 14 );
			
			
		// PUBLIC FUNCTIONS
		}else{
		
			// LOAD IN CURRENCY VALUES
			add_action('init', array($this, '_currencylist' ) );
			
			// ADD BASKET TO hook_welcometext
			if(!defined('WLT_CART_NOBASKETTOP')){
			 add_action('hook_welcometext', array($this, '_hook_welcometext' ) );
			}
			
			// START CURRENY INCLUSION			
			add_action('hook_price_filter',array($this, '_curreny_extra_tax'), 1);
			add_action('hook_price_filter',array($this, '_currency'), 2);			
			//add_action('hook_price_currencycode',array($this, '_currencycode'));
			
			// HOOK INTO CART
			add_action('hook_cart_data','basic_tax_calculate');
			 
			// HOOK INTO CORE SYSTEM	
			add_action('hook_item_pre_code', array($this, '_shop_defaultdisplay' ) );
			add_action('wp_footer', array($this, '_shop_footer') );	
			add_action('wp_head', array($this, '_extracss' ) );
			
			// HOOK INTO INIT FOR DOWNLOAD
			add_action('init', array($this, '_downloadproduct' ) );	
			
			 // CHECK FOR GUEST DATA
			add_action('init', array($this , '_saveguestdata' ) );
			
			// HOOK INTO USERS ACCOUNT AND ADD IN BILLING/DELIVERY ADDRESS FIELDS
			add_action('hook_account_mydetails_after', array($this, '_userfields' ) );
			add_action('hook_account_update', array($this, '_hook_account_update' ) );
			
			// SHORTCODEES
			add_shortcode( 'INSTOCK', array($this,'shortcode_instock') );
			add_shortcode( 'ADDBOX', array($this,'shortcode_addbox') );
			
			
			add_action('hook_header_style6', array($this, '_hook_header_style6' ) );	
			
		}	 
	}
	
	
function _hook_header_style6(){

// GET DISPLAY DATA
$core_admin_values = get_option("core_admin_values");  
$st = $core_admin_values['shoptop'];

ob_start();
?> 
 
<div class="col-md-4 col-sm-5 col-xs-12" id="core_logo">

<a href="<?php echo get_home_url(); ?>/" title="<?php echo get_bloginfo('name'); ?>"><?php echo hook_logo(true); ?></a></div>

<div class="col-md-8 col-sm-7 hidden-xs">

<div class="menuitems">
            <div class="row">
                <div class="col-md-4 text-center">
                
                	 <div class="text-area">
                	 <h3><?php echo stripslashes($st[1]['t']); ?></h3>
                	<img src="<?php echo get_template_directory_uri(); ?>/templates/template_shop_theme/img/cards.png" class="img-responsive" alt="cards" /> 
                    </div>
                    
                </div>
                <div class="col-md-4 text-center hidden-sm">
                	<div class="text-area icon2"><h3><?php echo stripslashes($st[2]['t']); ?></h3><p><?php echo stripslashes($st[2]['d']); ?></p></div>
                </div>
                
                <div class="col-md-4 text-center hidden-sm">
                  
                  <div class="text-area icon1"><h3><?php echo stripslashes($st[3]['t']); ?></h3><p><?php echo stripslashes($st[3]['d']); ?></p></div>
                  
                </div>
            </div>
        </div>
        
       
        
</div>
<?php
return ob_get_clean();
} 

function _hook_admin_2_homeedit($c){

 
$c['j1']['data']['b1'] = array( "t" => "break","txt" => "Side Box 1");

$c['j1']['data']['stxt1'] = array( "t" => "Box 1 Title", "d" => "Your Text Here" );
$c['j1']['data']['sdesc1'] = array( "t" => "Box 1 Description", "d" => "your sub description here" );
$c['j1']['data']['slink1'] = array( "t" => "Box 1 Link", "d" => "http://www.google.com" );
$c['j1']['data']['img1'] = array( "t" => "Box 1 Image<br><small>(size: 365px / 130px )</small>", 	"type" => "upload", "d" => CORE_THEME_PATH_IMG."b1.jpg" );

$c['j1']['data']['b2'] = array( "t" => "break","txt" => "Side Box 2");

$c['j1']['data']['stxt2'] = array( "t" => "Box 2 Title", "d" => "Your Text Here" );
$c['j1']['data']['sdesc2'] = array( "t" => "Box 2 Description", "d" => "your sub description here" );
$c['j1']['data']['slink2'] = array( "t" => "Box 2 Link", "d" => "http://www.google.com" );
$c['j1']['data']['img2'] = array( "t" => "Box 2 Image<br><small>(size: 365px / 130px )</small>", 	"type" => "upload", "d" => CORE_THEME_PATH_IMG."b2.jpg" );

$c['j1']['data']['b3'] = array( "t" => "break","txt" => "Side Box 3");

$c['j1']['data']['stxt3'] = array( "t" => "Box 3 Title", "d" => "Your Text Here" );
$c['j1']['data']['sdesc3'] = array( "t" => "Box 3 Description", "d" => "your sub description here" );
$c['j1']['data']['slink3'] = array( "t" => "Box 3 Link", "d" => "http://www.google.com" );
$c['j1']['data']['img3'] = array( "t" => "Box 3 Image<br><small>(size: 365px / 130px )</small>", 	"type" => "upload", "d" => CORE_THEME_PATH_IMG."b3.jpg" );

$c['t3']['data']['img1'] = array( "t" => "Box 1 Image<br><small>(size: 360px / 165px )</small>", 	"type" => "upload", "d" => "https://placeholdit.imgix.net/~text?txtsize=62&txt=Image+Here&w=360&h=165" ); 
$c['t3']['data']['img2'] = array( "t" => "Box 2 Image<br><small>(size: 360px / 165px )</small>", 	"type" => "upload", "d" => "https://placeholdit.imgix.net/~text?txtsize=62&txt=Image+Here&w=360&h=165" ); 
$c['t3']['data']['img3'] = array( "t" => "Box 3 Image<br><small>(size: 360px / 165px )</small>", 	"type" => "upload", "d" => "https://placeholdit.imgix.net/~text?txtsize=62&txt=Image+Here&w=360&h=165" ); 
 

return $c;
}

function shortcode_addbox(){ global $post, $userdata, $CORE;

// CAN CONTNIUE FLAG
$canContinue = true; $outOfStock = false;

// CHECK FOR MIN.ORDER AMOUNTS
$qty = get_post_meta($post->ID,'qty',true);
$qty_min = get_post_meta($post->ID,'qty_min',true);
if($qty == ""){ $qty = 10; }
if($qty_min == ""){ $qty_min = 1; }

// CHECK FOR OUT OF STOCK
if(is_numeric($qty) && $qty < 1){
$canContinue = false;
$outOfStock = true;
}

// GET PRODUCT TYPE
$product_type = get_post_meta($post->ID,'type',true);

// GET PRICE
$price = get_post_meta($post->ID,'price',true);

ob_start();
?>

<ul class="list-group">

    <li class="list-group-item item1">
    ID: <span>#<?php echo $post->ID; ?></span>
    </li>
    
    <li class="list-group-item item1">
    <?php echo do_shortcode('[FAVS]'); ?> <?php echo do_shortcode('[RATING style=1 small=1 class="pull-right"]'); ?>
    </li>

	<?php if($outOfStock): ?>
    
    <li class="list-group-item item2 text-center">
    <?php if(strlen(get_post_meta($post->ID,'stock_outofmsg',true)) > 1){ echo get_post_meta($post->ID,'stock_outofmsg',true); }else{  echo $CORE->_e(array('checkout','48')); } ?>
    </li>
    
    <?php else: ?>

    <li class="list-group-item item3">
    <?php echo $CORE->_e(array('checkout','56')); ?>: <span><?php echo $qty ." ".$CORE->_e(array('checkout','57')); ?></span>
    </li>

	<?php endif; ?> 
 
	<?php if($canContinue): ?>
  
		<?php if(is_numeric($qty_min) && $qty_min > 1): ?>
        
        <li class="list-group-item item6">
        <?php echo $CORE->_e(array('checkout','20'))." ".$qty_min." ".$CORE->_e(array('checkout','21')); ?>
        </li>
        
        <?php endif; ?>

		<li class="list-group-item item7">
        
<div class="row clearfix">
<div class="col-md-4"><label><?php echo $CORE->_e(array('checkout','3')); ?></label></div>
<div class="col-md-8">
    <div id="qtybox" class="clearfix">
    <input type="text" value="<?php echo $qty_min; ?>" onchange="checkqtyvalue(this.value);" id="qtyvalue">
    <a href="javascript:void(0);" class="btn button-minus qtyup"> <span><i class="fa fa-plus"></i></span> </a> 
    <a href="javascript:void(0);" class="btn button-plus qtydown"> <span><i class="fa fa-minus"></i></span> </a> 
    </div>
</div>
</div>
        

 
       
        

		

</li>

<?php $fgg = wlt_shop_custom_attributes($post->ID);  if(strlen($fgg) > 10){ ?>
<li class="list-group-item itemattb">
<?php echo $fgg; ?>
</li>
<?php } ?>

<?php if($price > 0): ?>

<li class="list-group-item text-center item8">

<div class="pricettag"><?php echo hook_price('<span id="wlt_listingpage_pricetag">'.$price.'</span>'); ?></div>	

</li>
<?php endif; ?>



<?php if($price == 0 && $product_type == "1"){ $download_count = get_post_meta($post->ID,'download_count',true); if($download_count == ""){ $download_count =0;} ?>

<li class="list-group-item text-center item11">
<?php echo $download_count.' '.$CORE->_e(array('checkout','22')); ?>
</li>

<?php } ?>

<li class="list-group-item item9">
<?php

 
// SWITCH PRODUCT TYPE FOR DISPLAY
switch($product_type){
			
				case "1": { // DOWNLOAD PRODUCT
				
					if($price == 0){ // download button for free downloads				
						if($userdata->ID){
						echo  '<form method="post" action="'.get_permalink($post->ID).'" style="margin:0px;">
						<input type="hidden" name="pid" value="'.$post->ID.'" />
						<input type="hidden" name="free" value="1" />
						<input type="hidden" name="downloadproduct" value="1" />';
						echo  "<button type='submit' class='btn btn-lg btn-primary' onclick=\"".$CORE_btn_add.";\">".$CORE->_e(array('checkout','18'))."</button>";
						echo  '</form>'; 
						}else{
						echo  "<button type='button' class='btn btn-lg btn-primary' onclick=\"alert('Members Only. Please login to download.');\">".$CORE->_e(array('checkout','18'))."</button>";
						}
					}else{					
						if(is_numeric($price) && $price != "" && $price > 0){	 // add cart button for products with a price				
						$CORE_btn_add = "addProduct('".session_id()."', '".get_home_url()."/', '".$post->ID."|".str_replace(",","",$price)."','".$GLOBALS['CORE_THEME']['links']['checkout']."')";				
						echo  "<a href='#addedToCart' data-toggle='modal' id='single_addcart_btn' class='btn btn-sm btn-primary' onclick=\"".$CORE_btn_add.";\">".$CORE->_e(array('checkout','16'))."</a>"; 
						$SINGLE_ADDCART_BUTTON = hook_addcart_big($SINGLE_ADDCART_BUTTON);				
						}					
					}
				
				} break;
				case "2": { // AFFILIATE PRODUCT
				
				echo hook_addcart_big("<a href='".get_home_url()."/out/".$post->ID."/buy_link/' id='single_addcart_btn' target='_blank' rel='nofollow' class='btn btn-lg btn-primary'>".$CORE->_e(array('checkout','16'))."</a>"); 
					
				} break;			
				default: { // NORMAL PRODUCT
				
					if(is_numeric($price) && $price != "" && $price > 0){	 // add cart button for products with a price				
					$CORE_btn_add = "addProduct('".session_id()."', '".get_home_url()."/', '".$post->ID."|".str_replace(",","",$price)."','".$GLOBALS['CORE_THEME']['links']['checkout']."')";	
								
				?>                
                
                <button type='button' id='single_addcart_btn' class='btn btn-lg btn-primary'><?php echo $CORE->_e(array('checkout','16')); ?></button> 
				
                <script>				
					jQuery(document).ready(function(){ 								
						jQuery('#single_addcart_btn').click(function() {					
							if(jQuery('#wlt_shop_required').val() == 1){
								<?php echo $CORE_btn_add; ?> 
								jQuery('#addedToCart').modal('show'); 
							}
						});									
					});				 
					</script>
                    
                    <?php
					 
					 			
					}
				
				} break;	
						
			}// end switch

?>
</li>

<?php endif; // can continue ?>

</ul>

<script>
 
var max_amount = <?php echo $qty; ?>;
jQuery(document).ready(function(){

	jQuery('#wlt_shop_qty_data').val(<?php echo $qty_min; ?>);
	
	jQuery("a.qtyup").click(function(){
		if(jQuery('#qtyvalue').val() < max_amount){
		jQuery('#qtyvalue').val(parseFloat(jQuery('#qtyvalue').val())+1);
		checkqtyvalue(jQuery('#qtyvalue').val());
		}
	}); 

	jQuery("a.qtydown").click(function(){
		if(jQuery('#qtyvalue').val() > 0){
		jQuery('#qtyvalue').val(parseFloat(jQuery('#qtyvalue').val())-1);
		checkqtyvalue(jQuery('#qtyvalue').val());
		}
	});   
 
});

function checkqtyvalue(c){

	if(c > max_amount){
		jQuery('#qtyvalue').val(max_amount);
		jQuery('#wlt_shop_qty_data').val(max_amount);
	}	
	jQuery('#wlt_shop_qty_data').val(c);	
} 
</script>
<?php

return ob_get_clean(); 
}
	
	function shortcode_instock($atts, $content = null){	global $post, $STRING, $CORE;
	
	extract( shortcode_atts( array( 'class' => '' ), $atts ) );	
	
		$QTY = get_post_meta($post->ID, 'qty', true);
		
		if($QTY == ""){ return; }
		
		if($QTY != ""){
			
			if($QTY == 0){
			$STRING = $CORE->_e(array('checkout','48'));
			}else{			
			$STRING = $QTY." ".$CORE->_e(array('checkout','57'));
			}
		
		}
		
		return "<span class='wlt_shortcode_instock ".$class."'>".$STRING."</span>";	
	
	}
	
	
	function _hook_account_update(){
	
		global $userdata, $wpdb;
	
		// SAVE THE CUSTOM PROFILE DATA
		if(isset($_POST['delivery']) && is_array($_POST['delivery'])){ 		 
			foreach($_POST['delivery'] as $key => $val){
				// SAVE DATA
				if(is_array($val)){
					update_user_meta($userdata->ID, strip_tags($key), $val);
				}else{
					update_user_meta($userdata->ID, strip_tags($key), esc_html(strip_tags($val)));
				}
			} // end foreach
		}// end if	
	
	}
	
	function _currencylist(){ 
	
	 $GLOBALS['shop_currency']	= array();
	 
	 // CREATE DEFAULT VALUE	
	 $GLOBALS['shop_currency'][$GLOBALS['CORE_THEME']['currency']['code']] 	= array(
		"code" => $GLOBALS['CORE_THEME']['currency']['code'], 
		"rate" => 1, 
		"symbol"=> $GLOBALS['CORE_THEME']['currency']['symbol'], 
		"link"	=> "c=".$GLOBALS['CORE_THEME']['currency']['code']
		);
	
	 $i=1; 
	 while($i < 6){ 
    
		if($GLOBALS['CORE_THEME']['cc']['symbol'.$i] == ""){ $i++; continue; }
		
		$GLOBALS['shop_currency'][$GLOBALS['CORE_THEME']['cc']['code'.$i]] 	= array(
		"code" => $GLOBALS['CORE_THEME']['cc']['code'.$i], 
		"rate" => $GLOBALS['CORE_THEME']['cc']['rate'.$i], 
		"symbol"=> $GLOBALS['CORE_THEME']['cc']['symbol'.$i] , 
		"link"=> "c=".$GLOBALS['CORE_THEME']['cc']['code'.$i]
		);
	
	 $i++; 
	 }
 	
	}
	
	function _extracss(){
		if(!defined('WLT_CHILDTHEME')){ 
		echo '<style type="text/css">#core_main_breadcrumbs_wrapper .myaccount { display:none; } </style>';
		}
	}
	
	// BASKET IN THE BREADCRUMBS
	function _hook_welcometext($c){ global $CORE_CART; return "<div class='hidden-xs' id='cartsm'> <ul class='list-inline'>".$this->_languagelist(true).''.$this->_currenylist(true)."</ul></div>";  }
 
	
	function _curreny_extra_tax($p){
	
	// DONT INCLUDE DISPLAY TAX ON CHECKOUT
	if(isset($GLOBALS['flag-checkout']) || isset($_GET['invoiceid']) || isset($GLOBALS['flag-callback']) ){ return $p; }
 	if(!isset($GLOBALS['CORE_THEME']['display_percentage']) || !is_numeric($GLOBALS['CORE_THEME']['display_percentage']) ){ return $p; }
		$p = strip_tags($p); 
		 if($p > 0){ 
			$p = str_replace(",","",$p);
			$p += ($p/100*$GLOBALS['CORE_THEME']['display_percentage']);	
			$p = round($p,2);			
			$seperator = "."; $sep = ","; $digs = 2; 
			if(is_numeric($p)){		
			$p = number_format($p,$digs, $seperator, $sep); 
			}		 
		}
		
		return $p;
	}
	
	// BLANKS OUT ARRAY FIELDS
	function _blankfields($c){
	unset($c['frontpage']);
	unset($c['topcategory']);
	unset($c['featured']);
	unset($c['html']);
	unset($c['visitorcounter']);
	unset($c['showgooglemap']);
	return $c;
	}
	// BLANKS OUT ARRAY FIELDS
	function _blankfields1($c){
	return array();
	}	
	// HOOK INTO THE EDIT LISTING PAGE
	function _store_fields($c){
	
	// unset package
	unset($c['packageID']);
	unset($c['listing_status']);
 
	 
		$list1 = array (
		"featured" => array("label" => "Featured Product?", "desc" => "Enable this if you want the product to be displayed with a highlighted background in search results.", "values" =>array("no"=>"No", "yes"=>"Yes" ) ), 
		
		"price" => array("label" => "Price", "desc" => "Product price, numerical values only." ),
		"old_price" => array("label" => "Old Price", "desc" => "Old Product price, numerical values only. Ideal for showing sales." ),  
		"sku" => array("label" => "SKU", "desc" => "Stock Keeping Unit" ), 
		"qty" => array("label" => "Quantity (0 = out of stock)", "desc" => "How many items you have available." ), 
		"qty_min" => array("label" => "Min. Order Qty", "desc" => "Force a minimum ordered amount" ), 
		"stock_remove" => array("label" => "Subtract Stock", "desc" => "", "values" =>array("0"=>"no", "1"=>"yes" )  ), 
		"stock_outofmsg" => array("label" => "Out Of Stock Status", "desc" => "This message is shown when the Quantity value is 0 or below." ), 
		"type" => array("label" => "Product Type", "desc" => "", "values" =>array("0"=>"Normal Product", "1"=>"Downloadable Product" , "2"=>"Affiliate Product" ) ),  
		 
			
		"tab2" => array("tab" => true, "title" => "Tax &amp; Shipping" ),
			"tax_required" => array("label" => "Add Tax?", "desc" => "", "values" =>array("0"=>"No", "1"=>"Yes" ) ), 
			"ship_required" => array("label" => "Add Shiping Charges?", "desc" => "", "values" =>array("0"=>"No", "1"=>"Yes" ) ), 
		"tab6" => array("tab" => true, "title" => "Product Dimensions" ),
		
			"weight_type" => array("label" => "Weight Range", "desc" => "This is a basic assumation which can be used to setup shipping charges.", "values" =>array("0"=>"Light", "1"=>"Medium", "2" => "Heavy", "3" => "Very Heavy" )), 
			
			"size_l" => array("label" => "Dimensions (Length)", "desc" => "" ), 
			"size_w" => array("label" => "Dimensions (Width)", "desc" => "" ), 
			"size_h" => array("label" => "Dimensions (Height)", "desc" => "" ), 
			"length_class" => array("label" => "Length Class", "desc" => "", "values" =>array("0"=>"Centimeter", "1"=>"Millimeter", "2" => "Inch" )), 
			"weight" => array("label" => "Weight", "desc" => "", "default" => "0.00" ),
			"weight_class" => array("label" => "Weight Class", "desc" => "", "values" =>array("0"=>"Kilogram", "1"=>"Gram", "2" => "Pound", "3" => "Ounce" )), 
			
			
		"tab4" => array("tab" => true, "title" => "Downloadable Product Settings"),		
			"download_path" => array("label" => "Download Path", "desc" => "This is the server path to the location of your file."  ),
		"tab5" => array("tab" => true, "title" => "Affiliate Product Settings"),		
			"buy_link" => array("label" => "Buy Link", "desc" => "" ),		
			
		"tab7" => array("tab" => true, "title" => "Product Tax"),		
			"tax_amount" => array("label" => "Tax Amount (%)", "desc" => "" ),	
		 	
				
				
		); 		 
		
	return array_merge($c,$list1);
	}
	
	
	
	
	
/* ========================================================================
 [COUPONS]
========================================================================== */ 
	function CODECODES_APPLYCART($c){
	$c['discount'] += $GLOBALS['CODECODES_DISCOUNT'];
	return $c;	
	}
/* =============================================================================
  CART FUNCTIONALITY
   ========================================================================== */
function WEIGHTCLASS($num){
	
	switch($num){
		case "1": {
			return "g";
		} break;
		case "2": {
			return "lb";
		} break;
		case "3": {
			return "oz";
		} break;
		default: { 
			return "KG";
		}
	}
}
function GETCART(){
		
		global $wpdb, $CORE; 
	 
		$cart_defaults = array("total" => 0, "subtotal" => 0, "qty" => 0, "tax" => 0, "weight_class" => 0, "weight" => 0,  "shipping" => 0, "comments" => "", "discount" => 0, "discount_code" => "", "session" => session_id(), "items" => array());
 		
		// IF GUEST CHECKOUT ADD-ON NEW VALUES
		if(isset($_SESSION['guestdata']) && !empty($_SESSION['guestdata']) ){		
		$cart_defaults['guest_data'] = $_SESSION['guestdata'];
		}
	 	 
		if(isset($_GET['emptycart'])){ unset($_SESSION['wlt_cart']); }
		 
		if(isset($_SESSION['wlt_cart']) && is_array($_SESSION['wlt_cart'])){
			// LOOP ITEMS
			foreach($_SESSION['wlt_cart'] as $key => $items){
				// GET INNER ITEM COUNT
				if(is_array($items)){
					foreach($items as $item){ 
						// TOTAL IS THE STORED ITEM PRICE X QTY
						$amount 					= get_post_meta($key,"price",true); 						
						if(!is_numeric($amount)){ 	$amount = 0; }
						// WEGIGHT
						$weight 					= get_post_meta($key,"weight",true); 
						$weight_class				= get_post_meta($key,"weight_class",true);						
						$cart_defaults['weight_class'] = $weight_class;							
						if(!is_numeric($weight)){ 	$weight = 0; }
						$cart_defaults['weight'] 	+= $weight*$item['qty'];						
						// QTY
						$cart_defaults['subtotal'] += $amount*$item['qty'];
						$cart_defaults['qty'] 	+= $item['qty'];
						$custom					= "";
						// CHECK FOR ADDITIONAL PRICE EXTRAS

						if(is_array($item['extra']['ship'])){ 
						$cart_defaults['shipping'] += $item['extra']['ship'];
						}// end if
						// CHECK FOR CUSTOM AMOUNTS
						if(is_array($item['extra']['custom']) && is_array($item['extra']['custom']) ){ 	
							$has_attributes = get_post_meta($key,"wlt_productattributes",true);					 
							foreach($item['extra']['custom'] as $custom_item){
							// CUSTOM FIELD ATTRIBUTES							
							$display = $custom_item['amount'];	
								// IF ITS A NUMERICAL VALUE, ASSUME ITS A PRICE				 
								if(is_numeric($custom_item['amount'])){								
									$cart_defaults['subtotal'] += ($custom_item['amount']*$item['qty']);						
									$amount += $custom_item['amount'];
									// GET THE DISPLAY TEXT FOR THIS AMOUNT
									if(is_array($has_attributes)){
									 //die(print_r($has_attributes));
										foreach($has_attributes['name'] as $k=>$att){										
											if($att == $custom_item['text']){
												$options = explode( PHP_EOL, $has_attributes['value'][$k] );
												if(is_array($options) && !empty($options)){
													foreach($options as $oval){													
													 if(strpos($oval,"[".$custom_item['amount']."]") !== false){
														$display_text = str_replace("[".$custom_item['amount']."]","",$oval)."+".hook_price($custom_item['amount']);
													 }
													}
												}
											}										 
										}// end foreach									
									}									
									if(isset($display_text)){
									$display = $display_text;
									}else{ 
									$display = hook_price($custom_item['amount']);
									}
								}// end if numeric
								
								// BUILD DISPLAYS TRING						
								$custom .= $custom_item['text'].": ".$display." ";
							} // end if
						}
						// CHECK FOR PRODUCT DISCOUNTS
						$current_discount_data = get_post_meta($key,"wlt_productdiscounts",true); 
						if(is_array($current_discount_data) && !empty($current_discount_data) ){
							$di=0; $num_discounts = count($current_discount_data);
							// LOOP DISCOUNTS
							while($di < $num_discounts){															 
								if(isset($current_discount_data['min'][$di]) && $item['qty'] >= $current_discount_data['min'][$di] && $item['qty'] <= $current_discount_data['max'][$di]){
									$old_item_price = get_post_meta($key,"price",true);
									$new_price_per_product = $current_discount_data['price'][$di];
									$new_discount = ($new_price_per_product*$item['qty']-$old_item_price*$item['qty']);
									if($new_discount < 0){
									$cart_defaults['discount'] += $new_discount;
									}
									//$amount = $new_price_per_product;
								}
							$di++;
							}
							 
							 $cart_defaults['discount'] = str_replace("-","",$cart_defaults['discount']);
						}						 			
						// IF WE ARE GETTING EVERYTHING, INCLUDE ALL OF THE PRODUCT INFORMATION						 
						$permalink = get_permalink($key);
						$image = "";
						if ( has_post_thumbnail($key) ) { 						
							$image = '<a href="'.$permalink.'" class="frame">';
							$image .= hook_image_display(get_the_post_thumbnail($key,'thumbnail',array('class'=> "wlt_thumbnail")));
							$image .= '</a>';	
						}else{
							// CHECK FOR FALLBACK IMAGE
							$fimage = $CORE->FALLBACK_IMAGE($key); 
							if($fimage !=""){ //&& !isset($GLOBALS['flag-single'])
							$image = '<a  href="'.$permalink.'" class="frame">';
							$image .= $fimage; 
							$image .= '</a>';
							}
						}
						$cart_defaults['items'][$key][] = 
						array (
						"innerID" 	=> $item['innerID'],
						"name" 		=> get_the_title($key), 
						"link" 		=> $permalink,
						"amount" 	=> $amount,
						"image" 	=> $image, 
						"qty"		=> $item['qty'], 
						"shipping" 	=> $item['extra']['ship'],
						"custom"	=> $custom, 
						);				
					} // end foreach
				} // end if
			} // enf foreach		
		} // end if
		
		// UPDATE COMMENTS
		if(isset($_SESSION['wlt_cart']['comment'])){ $cart_defaults['comments'] = stripslashes(strip_tags($_SESSION['wlt_cart']['comment'])); }
  	
		// CHECK FOR COUPON CODE		
		if(isset($_SESSION['discount_code']) && strlen($_SESSION['discount_code']) > 3 ){
			$cart_defaults['discount_code'] = strip_tags($_SESSION['discount_code']);
			$GLOBALS['CODECODES_DISCOUNT'] = $_SESSION['discount_code_value'];
			add_action('hook_cart_data', array( $this, 'CODECODES_APPLYCART') );
		}
		
		// HOOK INTO THE ARRAY
		$cart_defaults = hook_cart_data($cart_defaults);		
		// CALCULATE SUBTOTAL		
		$cart_defaults['total'] =  number_format((float)($cart_defaults['subtotal'] + $cart_defaults['shipping'] + $cart_defaults['tax']) - $cart_defaults['discount'], 2);		
		// RETURN COMPLETE ARRAY	 
		return $cart_defaults;
	}

	function UPDATECART(){	
	
		// WE ONLY PERFORM CART ACTIONS IF THE VALUE IS SET
		if(isset($_GET['cart_action'])){		
			
			switch($_GET['cart_action']){
			 
				case "addproduct": {
				
					// CHECK IF THE PRODUCT ALREADY EXISTS
					if(isset($_SESSION['wlt_cart'][$_GET['id']]) && is_numeric($_GET['existingID'])){
						$_SESSION['wlt_cart'][$_GET['id']][$_GET['existingID']+1]['qty'] ++;						 
						die();
					}elseif(isset($_SESSION['wlt_cart'][$_GET['id']])){
						$ProductArray = $_SESSION['wlt_cart'][$_GET['id']]; 				
						$innerID = count($_SESSION['wlt_cart'][$_GET['id']])+1;									
					}else{
						$ProductArray = array();
						$innerID = 1;
					}// end if	 
					
					// GENERATE A NEW ID FOR THIS ITEM					
					$ProductArray[$innerID]['innerID'] 	= $innerID;			 
					$ProductArray[$innerID]['qty'] 		= $_GET['qty'];
					// CHECK FOR EXTRAS
					$extras_array = array();
					if(strlen($_GET['extras']) > 0){ 
						$e1 = explode(",",$_GET['extras']);	 $o=1;										
						foreach($e1 as $ed){
							$bits = explode("|",$ed);
							if(isset($bits[1])){
							$extras_array[$o]['text'] 	= $bits[0];
							$extras_array[$o]['amount'] = $bits[1];
							$o++;
							} // end if
						} // end foreach
					}// end if
					$ProductArray[$innerID]['extra'] 	= array("ship" => $_GET['ship'], "custom" => $extras_array);
					
					// CHECK IF ANY OF THE EXISTING ENTRIES MATCH THIS ONE
					// THEN WE CAN UPDATE THE QTY INSTEAD OF ADDING A NEW PRODUCT
					if(isset($_SESSION['wlt_cart'][$_GET['id']])){
						// ONLY ONLY DIFFERENCES COULD BE THE CUSTOM ATTRIBUTES
						// SO LOOP AND CHECK IF THE ALREADY EXIST
						foreach($_SESSION['wlt_cart'][$_GET['id']] as $key=>$existing_item){						
							// IF WE FIND A MATCH, SIMPLY UPDATE THR QTY
							if($existing_item['extra'] == $ProductArray[$innerID]['extra']){
							$_SESSION['wlt_cart'][$_GET['id']][$key]['qty'] ++;							 
							return;
							}// end if					
						}// end foreach				
					}// end if
					// OTHERWISE SAVE
					$_SESSION['wlt_cart'][$_GET['id']] = $ProductArray;
					
					die(print_r($_SESSION));
 					 
				} break; // end add products	
				
				case "removeproduct" : {
	
					// FOR THE MOMENT, YOU REMOVE ALL ITEMS, NOT JUST 1
					if($_SESSION['wlt_cart'][$_GET['pid']][$_GET['nid']]['qty'] ==  1){
					unset($_SESSION['wlt_cart'][$_GET['pid']][$_GET['nid']]);
					}else{
					$_SESSION['wlt_cart'][$_GET['pid']][$_GET['nid']]['qty']--;
					}					
				} break;
				
				case "removeall" : {
	
					unset($_SESSION['wlt_cart'][$_GET['pid']][$_GET['nid']]);
									
				} break;
			
			} // end switch
		
		}// end if
		
	}// end function
	// BUILDS THE REMOVE ITEM BUTTON LINK
	function ADDITEM($pid, $nid,$price,$existingID = ''){
		 
		if(isset($GLOBALS['flag-single'])){
		$clink = get_permalink($post->ID);
		}else{
		$clink = $GLOBALS['CORE_THEME']['links']['checkout'];
		}
		$CORE_btn_add = "addProduct('".session_id()."', '".get_home_url()."/', '".$pid."|".str_replace(",","",$price)."|".$existingID."','".$clink."');setTimeout(function(){ rdirectmehere('".$clink."');}, 1000);";	
		 
		return $CORE_btn_add;	
	}
		
	// BUILDS THE REMOVE ITEM BUTTON LINK
	function REMOVEITEM($pid, $nid,$price, $removeall = ''){	 
	
		if(isset($GLOBALS['flag-single'])){
		$clink = get_permalink($post->ID);
		}else{
		$clink = $GLOBALS['CORE_THEME']['links']['checkout'];
		}
		
		if($removeall != ''){
		$CORE_btn_remove = "removeAll('".session_id()."', '".get_home_url()."', '".$pid."', '".$nid."', '".str_replace(",","",$price)."','".$clink."', '".$removeall."')";
		}else{
		$CORE_btn_remove = "removeProduct('".session_id()."', '".get_home_url()."', '".$pid."', '".$nid."', '".str_replace(",","",$price)."','".$clink."')";
		}
		
 
		return $CORE_btn_remove;	
	}
	
	
	
	
	
	
	
	
	

// ORDER TABLE
function _CHECKOUT(){ global $wpdb, $CORE; ?>

<table class="table table-bordered" id="cart_summary">

              <thead class="hidden-phone">
                <tr>
                  <th>#</th>
                  <th><?php echo $CORE->_e(array('checkout','1')); ?></th>
                  <th><?php echo $CORE->_e(array('checkout','2')); ?></th>
                  <th><?php echo $CORE->_e(array('checkout','3')); ?></th>
                  <th><?php echo $CORE->_e(array('checkout','4')); ?></th>                
                </tr>
              </thead>
              
			<tfoot>
                
               <?php if($GLOBALS['global_cart_data']['subtotal'] != 0 && is_numeric($GLOBALS['global_cart_data']['subtotal'])){ ?>
               <tr>
                  <td  class="hidden-phone"></td>
                  <td colspan="3" class="txtalignright"><?php echo $CORE->_e(array('checkout','6')); ?></td>
                  <td><?php echo $CORE->PRICE($GLOBALS['global_cart_data']['subtotal']); ?></td>
                </tr>
               <?php } ?>
               <?php if($GLOBALS['global_cart_data']['weight'] != 0 && is_numeric($GLOBALS['global_cart_data']['weight'])){ ?>
               <tr>
                  <td  class="hidden-phone"></td>
                  <td colspan="3" class="txtalignright"><?php echo $CORE->_e(array('checkout','54')); ?></td>
                  <td><?php echo $GLOBALS['global_cart_data']['weight'].$this->WEIGHTCLASS($GLOBALS['global_cart_data']['weight_class']); ?></td>
                </tr>
                <?php } ?>
               <?php if($GLOBALS['global_cart_data']['shipping'] != 0 && is_numeric($GLOBALS['global_cart_data']['shipping'])){ ?>
               <tr>
                  <td  class="hidden-phone"></td>
                  <td colspan="3" class="txtalignright"><?php echo $CORE->_e(array('checkout','7')); ?></td>
                  <td><?php echo $CORE->PRICE($GLOBALS['global_cart_data']['shipping']); ?></td>
                </tr>
                <?php } ?>
                <?php if($GLOBALS['global_cart_data']['tax'] != 0 && is_numeric($GLOBALS['global_cart_data']['tax'])){ ?>
               <tr>
                  <td  class="hidden-phone"></td>
                  <td colspan="3" class="txtalignright"><?php echo $CORE->_e(array('checkout','8')); ?></td>
                  <td><?php echo $CORE->PRICE($GLOBALS['global_cart_data']['tax']); ?></td>
                </tr>
                <?php } ?>
                <?php if($GLOBALS['global_cart_data']['discount'] != 0 && is_numeric($GLOBALS['global_cart_data']['discount'])){ ?>
               <tr>
                  <td  class="hidden-phone"></td>
                  <td colspan="3" class="txtalignright"><?php echo $CORE->_e(array('checkout','9')); ?></td>
                  <td><?php echo $CORE->PRICE($GLOBALS['global_cart_data']['discount']); ?></td>
                </tr>
                <?php } ?>
               
               <tr>
                  <td  class="hidden-phone"></td>
                  <td colspan="3" class="txtalignright total"><?php echo $CORE->_e(array('checkout','4')); ?></td>
                  <td><?php echo $CORE->PRICE($GLOBALS['global_cart_data']['total']); ?></td>
               </tr>
                             
              </tfoot>              
              
             <tbody>
              <?php
			  $counter = 1;
			 
			 if(is_array($GLOBALS['global_cart_data']['items'])){
			  foreach($GLOBALS['global_cart_data']['items'] as $key => $inner_item){ 
			  	foreach($inner_item as $innerkey => $item){ 
				 
				 
			  ?>
              	<!-- DESKTOP DISPLAY -->
                <tr id="table_row_<?php echo $counter; ?>"  class="hidden-phone">
                
                  <?php if(!isset($setflag)){ ?><td <?php echo 'rowspan="'.count($inner_item).'"';  ?>  class="hidden-phone"><?php echo $key; ?></td><?php  $setflag=1; } ?>
                  
                  <td class="_ptitle">
                  <a href="javascript:void(0);" onclick="jQuery('#table_row_<?php echo $counter; ?>').hide();<?php  echo $this->REMOVEITEM($key, $item['innerID'],$item['amount'], $item['qty']); ?>" class="cart_rproduct" title="<?php echo $CORE->_e(array('checkout','55')); ?>"><i class="glyphicon glyphicon-trash"></i></a>
                  
                  
                  <?php echo str_replace("img-polaroid","img-circle",$item['image']); ?><a href="<?php echo $item['link']; ?>"><?php echo $item['name']; ?></a>                  
                          
                  <?php if(strlen($item['custom']) > 1){ ?><p> <small><?php echo $item['custom']; ?></small></p><?php } ?>
                 
                  </td>
                  <td><?php echo $CORE->PRICE($item['amount']); ?></td>
                  <td class="qtytd">
                  <div class="row">
                  <div class="col-md-8"><div class="qty" id="qty<?php echo $counter; ?>"><?php echo $item['qty']; ?></div>
                  </div>
                  
                  <?php $qtyv = get_post_meta($key,'qty',true);  
				  
				  if( !is_admin() && ($qtyv > 1 || $qtyv == "")  ){ ?>
                  
                  <div class="col-md-4">
                  <?php if($item['qty'] < $qtyv){ ?>
                  <a rel="nofollow" class="cart_quantity_up" onclick="jQuery('#qty<?php echo $counter; ?>').text(parseFloat(jQuery('#qty<?php echo $counter; ?>').text())+1);<?php  echo $this->ADDITEM($key, $item['innerID'],$item['amount'], $innerkey); ?>">+</a> 
                 
                  <?php } ?>
                               
                  <a rel="nofollow" class="cart_quantity_down" onclick="removeboxme<?php echo $counter; ?>();">-</a>
                  
                   <script>
				  function removeboxme<?php echo $counter; ?>(){
				  				  
					  if(parseFloat(jQuery('#qty<?php echo $counter; ?>').text()) < 1){
					  	jQuery('#qty<?php echo $counter; ?>').text() = 0;
						jQuery('#table_row_<?php echo $counter; ?>').hide();
					  }
					  
					  jQuery('#qty<?php echo $counter; ?>').text(parseFloat(jQuery('#qty<?php echo $counter; ?>').text())-1);
					  <?php  echo $this->REMOVEITEM($key, $item['innerID'],$item['amount']); ?>
				  }				  
				  </script>
                  </div>
                  <?php } ?> 
                 </div>
                  </td>
                  <td><?php echo $CORE->PRICE($item['amount']*$item['qty']); ?></td>                  
                </tr>                
                
                <?php if(isset($core_admin_values['responsive']) && $core_admin_values['responsive'] == '1'){  ?> 
                <!-- MOBILE PHONE DISABLE -->
                <tr id="table_row_<?php echo $counter; ?>_mobile" class="visible-phone">
                     
                  <div style="border-bottom:1px solid #ccc;margin-bottom:10px;padding-bottom:5px;  font-size:11px;" class="visible-phone">
                  <a href="<?php echo $item['link']; ?>"><?php echo $item['name']; ?></a> 
                  <?php echo $CORE->PRICE($item['amount']*$item['qty']); ?> (<?php echo $item['qty']; ?>)               
                  <a href="javascript:void(0);" style="text-decoration:underline;color:red;" onclick="<?php if($item['qty'] ==1){ ?>jQuery('#table_row_<?php echo $counter; ?>_mobile').hide();<?php } echo $this->REMOVEITEM($key, $item['innerID'],$item['amount']); ?>">
				  <?php echo $CORE->_e(array('checkout','5')); ?></a>                  
                  <?php if(strlen($item['custom']) > 1){ ?><p> <small><?php echo $item['custom']; ?></small></p><?php } ?>
                  </div>
                              
                </tr> 
                <?php } ?>           
                
                
               <?php $counter++; } unset($setflag);  } } ?>             
               </tbody>
               <!-- MOBILE DISPLAY SECTION -->
              
            </table>   

<?php }
	
// CHECKOUT STEPS
function _CHECKOUTSTEPS(){ global $table_data, $CORE, $userdata, $wpdb; ?>

<?php hook_cart_checkoutsteps_top(); ?>

<input type="hidden" name="isGuestCheckout" id="isGuestCheckout" value="" />
<div class="accordion" id="wlt_checkoutsteps">

<div class="accordion-group">
    <div class="accordion-heading">
        <a class="accordion-toggle" data-toggle="collapse" data-parent="#wlt_checkoutsteps" href="#step1">
            <h3><?php echo $CORE->_e(array('checkout','23')); ?></h3>
        </a>
    </div>
	<div id="step1" class="accordion-body collapse in">
	<div class="accordion-inner">
    
    <?php if($userdata->ID){ // USER IS LOGGED IN ?>
    
    <h4 style="text-align:center;"><?php echo $CORE->_e(array('checkout','24')); ?> <?php echo $userdata->display_name; ?></h4>
     
    <script type="application/javascript">
	jQuery(document).ready(function(){
		jQuery('#step1').collapse('hide');
		jQuery('#step2').collapse('show');
	});
	</script>
    <?php }else{ ?>
	<div class="row-fluid">
    <div class="col-md-6 no_margin_left">
	
    	<h4><?php echo $CORE->_e(array('checkout','25')); ?></h4>
	
    	<p><?php echo $CORE->_e(array('checkout','26')); ?></p>

		<a class="btn btn-primary" href="<?php echo site_url('wp-login.php?action=register&redirect='.$GLOBALS['CORE_THEME']['links']['checkout']); ?>"><?php echo $CORE->_e(array('checkout','27')); ?></a>
		 
        <?php if($GLOBALS['CORE_THEME']['guestcheckout'] == 1){ ?>
        <a class="btn btn-default" href="<?php echo $GLOBALS['CORE_THEME']['links']['checkout']; ?>?guestcheckout=1"><?php echo $CORE->_e(array('checkout','52')); ?></a>
		<script type="application/javascript">
        <?php if(isset($_GET['guestcheckout'])){ ?>
		jQuery(document).ready(function(){ jQuery('#step1').collapse('hide');jQuery('#step2').collapse('show'); jQuery('#isGuestCheckout').val('?guestcheckout=1'); });
		<?php } ?>
        </script>
        
        <?php } ?>
    
    </div><div class="span5">
	
    	<h4><?php echo $CORE->_e(array('checkout','28')); ?></h4>
	
    	<p><?php echo $CORE->_e(array('checkout','29')); ?></p>

		<a class="btn btn-primary" href="<?php echo site_url('wp-login.php?action=login&redirect='.$GLOBALS['CORE_THEME']['links']['checkout']); ?>"><?php echo $CORE->_e(array('checkout','30')); ?></a>
        
	</div>
    </div>
   
<?php } ?>	

<div class="clearfix"></div>
		  
</div>
</div>
</div>

 
			
			
<div class="accordion-group">
    <div class="accordion-heading">
        <a class="accordion-toggle" data-toggle="collapse" data-parent="#wlt_checkoutsteps" href="#step2">
        <h3><?php echo $CORE->_e(array('checkout','31')); ?></h3>
        </a>
    </div>
    <?php if($userdata->ID || (isset($GLOBALS['CORE_THEME']['guestcheckout'] ) && $GLOBALS['CORE_THEME']['guestcheckout'] == 1) ){ ?>
    <div id="step2" class="accordion-body collapse">
        <div class="accordion-inner">
        <?php $this->_userfields($userdata->ID); ?>
         <script type="application/javascript">
			jQuery(document).ready(function(){
				jQuery('#billing_country').on('change', function(e){					 
					setTimeout(function (){
					var GuestCheckout = jQuery('#isGuestCheckout').val();
					if(GuestCheckout != ""){ 
						document.GuestCheckoutForm.submit();
					}else{
						var url = "<?php echo $GLOBALS['CORE_THEME']['links']['checkout']; ?>";
						jQuery(location).attr('href',url)
					}
				}, 2000);
				});
				jQuery('#billing_state').on('change', function(e){					 
					setTimeout(function (){
					var GuestCheckout = jQuery('#isGuestCheckout').val();
					if(GuestCheckout != ""){ 
						document.GuestCheckoutForm.submit();
					}else{
						var url = "<?php echo $GLOBALS['CORE_THEME']['links']['checkout']; ?>";
						jQuery(location).attr('href',url)
					}
				}, 2000);
				});
				
				jQuery('#wlt_checkoutsteps input:radio').on('change', function(e){					 
					setTimeout(function (){
					var GuestCheckout = jQuery('#isGuestCheckout').val();
					if(GuestCheckout != ""){ 
						document.GuestCheckoutForm.submit();
					}else{
						var url = "<?php echo $GLOBALS['CORE_THEME']['links']['checkout']; ?>";
						jQuery(location).attr('href',url)
					}
				}, 2000);
				});
				
			});
			</script>
        
      <div class="clearfix"></div>
      
       <hr />
       
       <div style="text-align:center;"><a href="javascript:void(0);" onclick="VALIDATE_DELIVERY_FORM_DATA();" class="btn btn-primary" id="continuestep3"><?php echo $CORE->_e(array('checkout','32')); ?></a></div>
        
        
        
      </div>      
    </div>
    <?php } ?>
</div>
			
			
<script type="application/javascript">
// VALIDATE DELIVERY DATA		
function VALIDATE_DELIVERY_FORM_DATA(){
var de1 	= document.getElementById("delivery1");
var de2 	= document.getElementById("delivery2");
var de3 	= document.getElementById("delivery3");
var de4 	= document.getElementById("delivery4");
var de5 	= document.getElementById("delivery5");
//var de6 	= document.getElementById("delivery6");
var de7 	= document.getElementById("delivery7");
var de8 	= document.getElementById("delivery8");
if(de1.value == '' || de2.value == '' || de3.value == '' || de4.value == '' || de5.value == '' || de7.value == '' || de8.value == ''){
alert('<?php echo $CORE->_e(array('validate','0')); ?>');
return false;
}
<?php if( !isset($GLOBALS['canContinueGuestCheckout']) && ( isset($_GET['guestcheckout']) && !isset($_POST['DformCompleted']) ) || (isset($_POST['DformCompleted']) && $_POST['DformCompleted'] != "yes" ) ){ ?>
jQuery('#DformCompleted').val('yes');
document.GuestCheckoutForm.submit();	
<?php }else{ ?>
// SAVE THE CART DATA IN A SESSION 
WLTSaveSession('<?php echo str_replace("https://","",str_replace("http://","",get_home_url())); ?>','core_ajax_callback');
// TOGGLE ONTO THE PAYMENT PAGE
jQuery('#wlt_checkoutsteps .collapse').collapse('toggle');	
<?php } ?>	
			
}
</script>

<div class="accordion-group">
    <div class="accordion-heading">
    <a class="accordion-toggle" data-toggle="collapse" data-parent="#wlt_checkoutsteps" href="#">
    <h3><?php echo $CORE->_e(array('checkout','33')); ?></h3>
    </a>
    </div>
		<?php if($userdata->ID || (isset($GLOBALS['CORE_THEME']['guestcheckout'] ) && $GLOBALS['CORE_THEME']['guestcheckout'] == 1) ){ ?>
        <div id="step3" class="accordion-body collapse">
        <div class="accordion-inner">
        
        <?php if(!isset($_GET['guestcheckout'])){ ?>
        <p><?php echo $CORE->_e(array('checkout','47')); ?> </p>
        <textarea style="width:96%;height:60px;" class="form-control" onchange="WLTUpdateUserField('<?php echo str_replace("http://","",str_replace("http://","",get_home_url())); ?>','cartcomment', this.value, 'cartcomment_ajax'); setTimeout(function(){location.reload()},500);"><?php if(isset($_SESSION['wlt_cart']['comment'])){ echo stripslashes($_SESSION['wlt_cart']['comment']); } ?></textarea>
        <div class="clearfix"></div>  
         <span id="cartcomment_ajax" style="font-size:11px;color:#666;">
         <?php if(isset($_SESSION['wlt_cart']['comment']) && strlen($_SESSION['wlt_cart']['comment']) > 1){ }else{ ?>
         No Comments Added
         <?php } ?>
         </span> 
        <?php } ?>
        
        <hr />
        <?php do_action('hook_checkout_before_paymentoptions'); ?>
        <?php if($GLOBALS['global_cart_data']['total'] > 0){ echo hook_checkout_paymentoptions($CORE->PAYMENTOPTIONS($GLOBALS['global_cart_data'])); } ?>
        <?php do_action('hook_checkout_after_paymentoptions'); ?>
        </div>
        <?php } ?> 
        
     <div class="clearfix"></div>   
        
    </div>
</div>      
<?php hook_cart_checkoutsteps_bottom(); ?>
<?php
	
	}
	// ADDON NEW USER FIELDS FOR BILLDING AND DELIVERY
	function _userfields($userid, $cFieldData = ""){  global $CORE, $userdata, $wpdb;
	
	if(isset($GLOBALS['flag-myaccount'])){ $userid = $userdata->ID; }
	
	if(is_admin()){
		// LOAD IN LANGUAGE
		$CORE->Language();
	}
 
 
	if(!isset($_GET['guestcheckout'])){
	$updateFieldCode = "onchange=\"WLTUpdateUserField('".str_replace("http://s","",str_replace("http://","",get_home_url()))."','xxx', this.value, 'core_ajax_callback');\"";
	$updateFieldCode1 = "onchange=\"jQuery('#checkoutstepsuserfields').hide();jQuery('#core_saving_wrapper').show();WLTUpdateUserField('".str_replace("https://","",str_replace("http://","",get_home_url()))."','xxx', this.value, 'core_ajax_callback');\"";
	}else{
	$updateFieldCode1 = "onchange=\"jQuery('#checkoutstepsuserfields').hide();jQuery('#core_saving_wrapper').show();\"";
	}
	?>
    
    <!-- SAVING CHANGES TEXT --->
    <div id="core_saving_wrapper" style="display:none;">
    <div class="alert alert-warning">
    <img src="<?php echo THEME_URI; ?>/framework/img/loading.gif" style="float:left; padding-right:30px;width:80px;" />
    <h1 style="padding-top:0px;margin-top:0px;"><?php echo $CORE->_e(array('add','29')); ?></h1>
    <p><?php echo $CORE->_e(array('add','30')); ?></p>
    <div class="clearfix"></div>
    </div>
    </div>
    <!-- END SAVING CHANGES --->
    
    <div id="checkoutstepsuserfields">
    
   <?php if(isset($GLOBALS['canContinueGuestCheckout'])){ ?>
   <script type="application/javascript">
	jQuery(document).ready(function(){
			VALIDATE_DELIVERY_FORM_DATA();
			jQuery('#step1').collapse('hide');
			jQuery('#step2').collapse('hide');
			jQuery('#step3').collapse('show');
	});
   </script>
<?php } ?>
   
   <?php if(isset($_GET['guestcheckout'])){ ?>  
   
   <form method="post" action="<?php echo $GLOBALS['CORE_THEME']['links']['checkout']; ?>?guestcheckout=1" id="GuestCheckoutForm" name="GuestCheckoutForm">
   <input type="hidden" name="DformCompleted" id="DformCompleted" value="" />
   <?php } ?>
    
   <div class="row">
    	
         <div class="col-md-6">
					  <div class="form-group col-md-11">
						<label class="control-label"><?php echo $CORE->_e(array('checkout','35')); ?> <span class="required">*</span></label>
						<div class="controls docs-input-sizes">
						  <input type="text" <?php if(isset($GLOBALS['flag-checkout']) && $userdata->ID){ echo str_replace("xxx","billing_fname",$updateFieldCode); } ?> class="form-control" name="delivery[billing_fname]" value="<?php 
						  if(isset($_POST['delivery'])){ echo strip_tags($_POST['delivery']['billing_fname']); }
						  elseif(is_admin() && is_array($cFieldData) ){ echo $cFieldData['billing_fname']; }
						  elseif($userid){ echo get_user_meta($userid, "billing_fname",true); } ?>" id="delivery1" <?php if(is_admin() && is_array($cFieldData)){ echo "disabled=disabled"; } ?>>
                          
                          
						</div>
					  </div>
					  <div class="form-group col-md-11">
						<label class="control-label"><?php echo $CORE->_e(array('checkout','36')); ?> <span class="required">*</span></label>
						<div class="controls docs-input-sizes">
						  <input type="text" <?php if(isset($GLOBALS['flag-checkout']) && $userid){ echo str_replace("xxx","billing_lname",$updateFieldCode); } ?> class="form-control" name="delivery[billing_lname]" value="<?php 
						  if(isset($_POST['delivery'])){ echo strip_tags($_POST['delivery']['billing_lname']); }
						  elseif(is_admin() && is_array($cFieldData) ){ echo $cFieldData['billing_lname']; }
						  elseif($userid){ echo get_user_meta($userid, "billing_lname",true); } ?>" id="delivery2" <?php if(is_admin() && is_array($cFieldData)){ echo "disabled=disabled"; } ?>>
						</div>
					  </div>					  
					  <div class="form-group col-md-11">
						<label class="control-label"><?php echo $CORE->_e(array('checkout','37')); ?> <span class="required">*</span></label>
						<div class="controls docs-input-sizes">
						  <input type="text" <?php if(isset($GLOBALS['flag-checkout']) && $userid){ echo str_replace("xxx","billing_email",$updateFieldCode); } ?> class="form-control" name="delivery[billing_email]" value="<?php 
						  if(isset($_POST['delivery'])){ echo strip_tags($_POST['delivery']['billing_email']); }
						  elseif(is_admin() && is_array($cFieldData) ){ echo $cFieldData['billing_email']; }
						  elseif($userid){ echo get_user_meta($userid, "billing_email",true); } ?>" id="delivery3" <?php if(is_admin() && is_array($cFieldData)){ echo "disabled=disabled"; } ?>>
						</div>
					  </div>					 

					  <div class="form-group col-md-11">
						<label class="control-label"><?php echo $CORE->_e(array('checkout','38')); ?> <span class="required">*</span></label>
						<div class="controls docs-input-sizes">
						  <input type="text" <?php if(isset($GLOBALS['flag-checkout']) && $userid){ echo str_replace("xxx","billing_phone",$updateFieldCode); } ?> class="form-control" name="delivery[billing_phone]" value="<?php 
						  if(isset($_POST['delivery'])){ echo strip_tags($_POST['delivery']['billing_phone']); }
						  elseif(is_admin() && is_array($cFieldData) ){ echo $cFieldData['billing_phone']; }
						  elseif($userid){ echo get_user_meta($userid, "billing_phone",true); } ?>" id="delivery4" <?php if(is_admin() && is_array($cFieldData)){ echo "disabled=disabled"; } ?>>
						</div>
					  </div>
                      
                      
                       <div class="form-group col-md-11">
						<label class="control-label"><?php echo $CORE->_e(array('checkout','39')); ?> <span class="required">*</span></label>
						<div class="controls docs-input-sizes">
							  <?php $selected_country = ""; 
							   
							  if(isset($_POST['delivery'])){ $selected_country = $_POST['delivery']['billing_country']; }
							  elseif(is_admin() && is_array($cFieldData) ){ $selected_country = $cFieldData['billing_country']; }
							  elseif(is_admin()){ $selected_country = get_user_meta($userid, "billing_country",true); }
							  elseif($userid){ $selected_country = get_user_meta($userid, "billing_country",true); }  ?>
                              <select class="form-control" id="billing_country" name="delivery[billing_country]" <?php 
							  if(isset($GLOBALS['flag-checkout']) && $userid){ echo str_replace("xxx","billing_country",$updateFieldCode); }elseif(isset($_GET['guestcheckout'])){ echo $updateFieldCode1; } ?> 
                              <option></option>
							  <?php if(is_admin() && is_array($cFieldData)){ echo "disabled=disabled"; } ?>>
                              <?php foreach($GLOBALS['core_country_list'] as $key=>$value){
								if(isset($selected_country) && $selected_country == $key){ $sel ="selected=selected"; }else{ $sel =""; }
								echo "<option ".$sel." value='".$key."'>".$value."</option>";} ?>
                              </select>  
						</div>
					  </div>
                      
            <script>
			jQuery(document).ready(function(){
				jQuery( "#billing_country" ).change(function() {						
					 var ef = jQuery( "#billing_country" ).val();
					 jQuery('#billing_state').children().attr('selected','selected');
					  
				});		
			});			 
			</script> 
					 
                      
                      
            <?php 
			
			 if(isset($GLOBALS['CORE_THEME']['cart_method_list']) && is_array($GLOBALS['CORE_THEME']['cart_method_list'])){ 
			 
			 	$estring = "";
			 	
				if($userid && !isset($_GET['guestcheckout'])){ $sbm = get_user_meta($userid, "billing_method",true); } elseif(isset($_GET['guestcheckout']) && isset($_POST['delivery']['billing_method']) ){ $sbm = $_POST['delivery']['billing_method']; }
				
				if(isset($GLOBALS['flag-checkout']) && $userid){ $ff = str_replace("xxx","billing_method",$updateFieldCode1); }  
				foreach($GLOBALS['CORE_THEME']['cart_method_list'] as $method){ if(strlen($method) > 1){
			
					if(isset($GLOBALS['flag-checkout']) && $userid){ $ff = str_replace("xxx","billing_method",str_replace("this.value","'".$method."'",$updateFieldCode1)); } elseif(isset($_GET['guestcheckout'])){ $ff = $updateFieldCode1; }
					
					if($sbm == $method){ $ff.=" checked=checked"; }				
					
					if(is_admin()){
						if($sbm == $method){
						$estring .= "".$method."";
						}					
					}else{
					$estring .= "<div class='checkout'><input type='radio' name='delivery[billing_method]' value='".$method."' ".$ff."> ".$method."</div>";
					}// end if
					
				} }
			}  	
			
			// CHECK FOR DELIVERY METHODS
			if(isset($estring) && strlen($estring) > 1){ ?>
            <p><b><?php echo $CORE->_e(array('checkout','40')); ?></b></p>    
            <?php echo $estring; ?>       
            <?php } ?> 
                      
					   </div><div class="col-md-6">			
            
					  <div class="form-group col-md-11">
						<label class="control-label"><?php echo $CORE->_e(array('checkout','41')); ?> <span class="required">*</span></label>
						<div class="controls docs-input-sizes">
						  <input type="text" <?php if(isset($GLOBALS['flag-checkout']) && $userid){ echo str_replace("xxx","billing_address",$updateFieldCode); } ?> class="form-control" name="delivery[billing_address]" value="<?php 
						  if(isset($_POST['delivery'])){ echo strip_tags($_POST['delivery']['billing_address']); }
						  elseif(is_admin() && is_array($cFieldData) ){ echo $cFieldData['billing_address']; }
						  elseif($userid){ echo get_user_meta($userid, "billing_address",true); } ?>" id="delivery5" <?php if(is_admin() && is_array($cFieldData)){ echo "disabled=disabled"; } ?>>
						</div>
					  </div>
                      
					  <div class="form-group col-md-11">
						<label class="control-label"><?php echo $CORE->_e(array('checkout','42')); ?></label>
						<div class="controls docs-input-sizes">
						  <input type="text" <?php if(isset($GLOBALS['flag-checkout']) && $userid){ echo str_replace("xxx","billing_address2",$updateFieldCode); } ?> class="form-control" name="delivery[billing_address2]" value="<?php 
						  if(isset($_POST['delivery'])){ echo strip_tags($_POST['delivery']['billing_address2']); }
						  elseif(is_admin() && is_array($cFieldData) ){ echo $cFieldData['billing_address2']; }
						  elseif($userid){ echo get_user_meta($userid, "billing_address2",true); } ?>" id="delivery6" <?php if(is_admin() && is_array($cFieldData)){ echo "disabled=disabled"; } ?>>
						</div>
					  </div>
                      
                      <div class="form-group col-md-11">
						<label class="control-label"><?php echo $CORE->_e(array('checkout','43')); ?> <span class="required">*</span></label>
						<div class="controls docs-input-sizes">
						  <input type="text" <?php if(isset($GLOBALS['flag-checkout']) && $userid){ echo str_replace("xxx","billing_city",$updateFieldCode); } ?> class="form-control" name="delivery[billing_city]" value="<?php 
						  if(isset($_POST['delivery'])){ echo strip_tags($_POST['delivery']['billing_city']); }
						  elseif(is_admin() && is_array($cFieldData) ){ echo $cFieldData['billing_city']; }
						  elseif($userid){ echo get_user_meta($userid, "billing_city",true); } ?>" id="delivery7" <?php if(is_admin() && is_array($cFieldData)){ echo "disabled=disabled"; } ?>>
						</div>
					  </div>
                      
					  <div class="form-group col-md-11">
						<label class="control-label"><?php echo $CORE->_e(array('checkout','44')); ?> <span class="required">*</span></label>
						<div class="controls docs-input-sizes">
						  <input type="text" <?php if(isset($GLOBALS['flag-checkout']) && $userid){ echo str_replace("xxx","billing_zip",$updateFieldCode); } ?> s name="delivery[billing_zip]"  class="form-control" value="<?php 
						  if(isset($_POST['delivery'])){ echo strip_tags($_POST['delivery']['billing_zip']); }
						  elseif(is_admin() && is_array($cFieldData) ){ echo $cFieldData['billing_zip']; }
						  elseif($userid){ echo get_user_meta($userid, "billing_zip",true); } ?>" id="delivery8" <?php if(is_admin() && is_array($cFieldData)){ echo "disabled=disabled"; } ?>>
						</div>
					  </div>
                        
                      
                      <div class="form-group col-md-11">
						<label class="control-label"><?php echo $CORE->_e(array('checkout','45')); ?> <span class="required">*</span></label>
						<div class="controls docs-input-sizes">
							  <?php 
							  if(isset($_POST['delivery'])){ $selected_state = $_POST['delivery']['billing_state']; }
							  elseif(is_admin() && is_array($cFieldData) ){ $selected_state = $cFieldData['billing_state']; }
							  elseif(is_admin()){ $selected_state = get_user_meta($userid, "billing_state",true); }	
							  elseif($userid){ $selected_state = get_user_meta($userid, "billing_state",true); }   ?>
                              <select id="billing_state" class="form-control" name="delivery[billing_state]" <?php if(isset($GLOBALS['flag-checkout']) && $userid){ echo str_replace("xxx","billing_state",$updateFieldCode1); }elseif(isset($_GET['guestcheckout'])){ echo $updateFieldCode1; } ?> <?php if(is_admin() && is_array($cFieldData)){ echo "disabled=disabled"; } ?>>
                              <option value=""></option>
                              <?php 
							  if($selected_country != ""){ $ddf = "selected=selected"; }else{ $ddf = ""; }	
							   					  
							  		// NOW LETS CHECK FOR STATES
									if(isset($GLOBALS['core_state_list'][$selected_country])){
										$bits = explode("|",$GLOBALS['core_state_list'][$selected_country]);
										foreach($bits as $st){
											if(isset($selected_state) && $selected_state == $st){ $sel ="selected=selected"; }else{ $sel =""; }
											echo '<option value="'.$st.'" '.$sel.'>'.$st.'</option>';
										} // end if							
									}// end if						   
							  	 
							 
								?>
                              </select>  
						</div>
					  </div>
                      
				 </div>
    </div>
    
   <?php if(isset($GLOBALS['flag-account'])){ ?>
    <script type="application/javascript">
			jQuery(document).ready(function(){
				jQuery('#billing_country').on('change', function(e){
						document.myaccountdataform.submit();
				}); 				
			});
	</script>
    <?php } ?>
    
    
    <?php if(isset($_GET['guestcheckout'])){ ?></form><?php } ?>
    
    </div><!-- end checkoutstepuserfields -->
    
    <?php
	
	}
	
	
	// DISPLAYS THE SHOPPING CART/BASKET AT THE TOP OF THE PAGE
	function _BASKET($showli=true){ global $CORE, $wpdb; 
	
	if(isset($GLOBALS['BASKETSET'])){ return ""; }else{ $GLOBALS['BASKETSET'] = true; } 
	 
	// GET CART DAT
	$cart_data = $this->GETCART(true); 	
 
	
	if(get_option('users_can_register') != '1'){ $styleextra = " right"; }else{ $styleextra = ""; }
	if($showli){ $catstring = '<li class="nodivider '.$styleextra.'">'; }
	 
	  
	$catstring = "<div class='wlt_cartboxwrap'>
	<div id='wlt_cartbox'>	
	
	<div class='btn-group hidemobilecart'>
	
	<div id='wlt_cart_qty'>".$cart_data['qty']."</div>
	
		<div class='dropdown-toggle' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false' role='button'> 
		
		<span class='ct'>My Cart <span class='caret'></span> </span>
		
		 ".hook_price('<span id="wlt_cart_total">'.$cart_data['total'].'</span>')." </div> ";	 
	  
	$catstring .= '<ul class="dropdown-menu" id="wlt_cartproducts_dropdown">';
 	
	// LOOP ALL ITEMS AND SHOW THEM
	if(isset($cart_data['items']) && is_array($cart_data['items'])){
		foreach($cart_data['items'] as $key=>$item){
			foreach($item as $mainitem){
			$catstring .= '<li>
			<a href="'.$mainitem['link'].'">'.str_replace("","",strip_tags($mainitem['image'], '<img>')).' '.$mainitem['name'].' 
			<div class="extrainfo"><span class="pricetag">'.hook_price($mainitem['amount']).'</span> <span class="customtag">'.$mainitem['custom'].'&nbsp;<span> <div class="clearfix"></div></div></a>
			</li>';
			}
		}		
		$catstring .= '<li class="checkoutnow"><a href="'.$GLOBALS['CORE_THEME']['links']['checkout'].'">'.$CORE->_e(array('checkout','14')).'</a></li>';
	}else{
		$catstring .= '<li class="emptybasket">'.$CORE->_e(array('checkout','46')).'</li>';
	}
			
	$catstring .= '</ul> ';
 
	$catstring .= '</div> </div></div>';
	
	if($showli){ $catstring .= '</li>'; }
	
	 
	
	 $catstring .= "<script>jQuery('#wlt_cart_qty').click(function(){ window.location.href = '".$GLOBALS['CORE_THEME']['links']['checkout']."'; });</script>";
    
    
    
	
	return $catstring;
	
	}
	
	
	
	
 
	//1. HOOK INTO THE ADMIN MENU TO CREATE A NEW TAB
	function _hook_admin_1_pagesetup(){  global $wpdb, $CORE; $core_admin_values = get_option("core_admin_values");  ?>
    
    
        <div class="accordion-group">
    <div class="accordion-heading" style="background:#fff;">
        <a class="accordion-toggle collapsed" data-toggle="collapse" data-parent="#pagesetup_according" href="#extra1">
         <h4 style="margin:0xp;font-weight:bold;">
         <img src="<?php echo get_template_directory_uri(); ?>/framework/admin/img/icons/set.png">
         Shopping Cart Settings <span style="font-size:12px;">(view/hide)</span></h4> 
        </a>
    </div>
    
    <div id="extra1" class="accordion-body collapse">
    <div class="accordion-inner">
    <div class="innerwrap content">
    
     <div class="heading2">Checkout Options</div>
    
	  <div class="form-row control-group row-fluid">
                            <label class="control-label span7">Guest Checkout</label>
                            <div class="controls span4">
                              <div class="row-fluid">
                                <div class="pull-left">
                                  <label class="radio off">
                                  <input type="radio" name="toggle" 
                                  value="off" onchange="document.getElementById('guestcheckout').value='0'">
                                  </label>
                                  <label class="radio on">
                                  <input type="radio" name="toggle"
                                  value="on" onchange="document.getElementById('guestcheckout').value='1'">
                                  </label>
                                  <div class="toggle <?php if($core_admin_values['guestcheckout'] == '1'){  ?>on<?php } ?>">
                                    <div class="yes">ON</div>
                                    <div class="switch"></div>
                                    <div class="no">OFF</div>
                                  </div>
                                </div> 
                               </div>
                             </div>
                             
                             <input type="hidden" class="row-fluid" id="guestcheckout" name="admin_values[guestcheckout]" 
                             value="<?php echo $core_admin_values['guestcheckout']; ?>">
            </div> 
    
    
  
    <div class="heading2">Language Drop down</div>
    	
        <div class="form-row control-group row-fluid ">
                                <label class="control-label span7" data-placement="top">Enable Display</label>
                                <div class="controls span4">
                                  <div class="row-fluid">
                                    <div class="pull-left">
                                      <label class="radio off">
                                      <input type="radio" name="toggle" 
                                      value="off" onchange="document.getElementById('shop_languagedropdown').value='0'">
                                      </label>
                                      <label class="radio on">
                                      <input type="radio" name="toggle"
                                      value="on" onchange="document.getElementById('shop_languagedropdown').value='1'">
                                      </label>
                                      <div class="toggle <?php if($core_admin_values['shop_languagedropdown'] == '1'){  ?>on<?php } ?>">
                                        <div class="yes">ON</div>
                                        <div class="switch"></div>
                                        <div class="no">OFF</div>
                                      </div>
                                    </div> 
                                   </div>
                                 </div>
                                 
                                 <input type="hidden" class="row-fluid" id="shop_languagedropdown" name="admin_values[shop_languagedropdown]" 
                                 value="<?php echo $core_admin_values['shop_languagedropdown']; ?>">
         </div>
         

 
    
    <div class="heading2">Currency Drop down</div>
    
        <div class="form-row control-group row-fluid ">
                                <label class="control-label span7" data-placement="top">Enable Display</label>
                                <div class="controls span4">
                                  <div class="row-fluid">
                                    <div class="pull-left">
                                      <label class="radio off">
                                      <input type="radio" name="toggle" 
                                      value="off" onchange="document.getElementById('shop_currencydropdown').value='0'">
                                      </label>
                                      <label class="radio on">
                                      <input type="radio" name="toggle"
                                      value="on" onchange="document.getElementById('shop_currencydropdown').value='1'">
                                      </label>
                                      <div class="toggle <?php if($core_admin_values['shop_currencydropdown'] == '1'){  ?>on<?php } ?>">
                                        <div class="yes">ON</div>
                                        <div class="switch"></div>
                                        <div class="no">OFF</div>
                                      </div>
                                    </div> 
                                   </div>
                                 </div>
                                 
                                 <input type="hidden" class="row-fluid" id="shop_currencydropdown" name="admin_values[shop_currencydropdown]" 
                                 value="<?php echo $core_admin_values['shop_currencydropdown']; ?>">
         </div>
         
         
         
	<div class="row-fluid">
    <div class="span6">
        <div class="form-row control-group row-fluid">
       <label class="control-label span4" for="normal-field">Symbol ($)</label>
    <div class="controls span7">
    	<input type="text" name="admin_values[currency][symbol]" class="row-fluid" value="<?php echo $core_admin_values['currency']['symbol']; ?>">
    </div>
        </div>
    </div>
    <div class="span6">
        <div class="form-row control-group row-fluid">
        <label class="control-label span4" for="normal-field">Code (USD)</label>
    <div class="controls span7">
    	<input type="text" name="admin_values[currency][code]" class="row-fluid" value="<?php echo $core_admin_values['currency']['code']; ?>">
    </div>
        </div>    
    </div>   
    </div>
     <input type="hidden" name="admin_values[currency][position]" class="row-fluid" value="<?php echo $core_admin_values['currency']['position']; ?>">
         
         
         <div class="form-row control-group row-fluid">
        <label class="control-label span5" for="style">Default Currency List Value</label>
        <div class="controls span6">
        <select name="admin_values[shop_defaultcurrency]" class="chzn-select" id="shop_defaultcurrency">         
        <?php $i=1;  while($i < 6){ if($core_admin_values['cc']['code'.$i] == ""){ $i++; continue; } ?>
        <option value="<?php echo $core_admin_values['cc']['code'.$i]; ?>" <?php if($core_admin_values['shop_defaultcurrency'] == $core_admin_values['cc']['code'.$i]){ echo "selected=selected"; } ?>><?php echo $core_admin_values['cc']['code'.$i]; ?></option>
        <?php $i++; } ?>        
        </select>
        </div>
        </div> 
        
        <p class="alert">Note. Your default price currency code is here in your order <a href="admin.php?page=6&tab=gateways" style="text-decoration:underline;font-weight:bold;">manager here.</a></p>
    
    
    	<hr />
        
        
    <div class="heading2">Currency Values</div>
    <p>Please remember the base currency rate is always set to 1 therefore you should ensure your rates below reflect the price against your base currency.</p>
    <p>For example, if your base currency is GBP. Then the USD rate would be compared against the GBP.</p>
    <p>Check the latest rates here: <a href="http://finance.yahoo.com/currency-converter/#from=GBP;to=USD;amt=1" target="_blank" style="text-decoration:underline;">here</a>
    <hr />
    
    
    <?php 
	
	if(!isset($core_admin_values['cc']['symbol1'])){	
	
	$core_admin_values['cc']['symbol1'] = "&pound;";
	$core_admin_values['cc']['code1'] = "GBP";
	$core_admin_values['cc']['rate1'] = "1.6799";
	
	$core_admin_values['cc']['symbol2'] = "&euro;";
	$core_admin_values['cc']['code2'] = "EUR";
	$core_admin_values['cc']['rate2'] = "1.3849";
	
	$core_admin_values['cc']['symbol3'] = "C$";
	$core_admin_values['cc']['code3'] = "CAD";
	$core_admin_values['cc']['rate3'] = "0.9175";
	
	$core_admin_values['cc']['symbol4'] = "$";
	$core_admin_values['cc']['code4'] = "AUD";
	$core_admin_values['cc']['rate4'] = "0.9371";
	
	$core_admin_values['cc']['symbol5'] = "&yen;";
	$core_admin_values['cc']['code5'] = "JPY";
	$core_admin_values['cc']['rate5'] = "0.0098";
			
	}
	
	
	$i=1; while($i < 6){ ?>
    
	<div class="row-fluid">
    
    <div class="span4">
        <div class="form-row control-group row-fluid">
        <label class="control-label span4" for="normal-field" rel="tooltip" data-original-title="Example $" data-placement="top">Symbol</label>
        <div class="controls span7">
            <input type="text" name="admin_values[cc][symbol<?php echo $i; ?>]" class="row-fluid" value="<?php echo $core_admin_values['cc']['symbol'.$i]; ?>">
        </div>
        </div>
    </div>
    
    <div class="span4">
        <div class="form-row control-group row-fluid" rel="tooltip" data-original-title="Example USD" data-placement="top">
        <label class="control-label span4" for="normal-field">Code</label>
        <div class="controls span7">
            <input type="text" name="admin_values[cc][code<?php echo $i; ?>]" class="row-fluid" value="<?php echo $core_admin_values['cc']['code'.$i]; ?>">
        </div>
        </div>    
    </div> 
    
    <div class="span4">
        <div class="form-row control-group row-fluid" rel="tooltip" data-original-title="Example 1.144" data-placement="top">
        <label class="control-label span4" for="normal-field">Rate</label>
        <div class="controls span7">
            <input type="text" name="admin_values[cc][rate<?php echo $i; ?>]" class="row-fluid" value="<?php echo $core_admin_values['cc']['rate'.$i]; ?>">
        </div>
        </div>    
    </div>     
      
    </div>
    <?php $i++; } ?>

    
    </div>
    
	
     
  
   
   
    </div>
    </div>
</div>
	
	  
  
    
 
    
    
    <?php }
	
	function _saveguestdata(){
	
		if(isset($_POST['DformCompleted']) && $_POST['DformCompleted'] == "yes"){
		
		$_SESSION['guestdata'] = $_POST['delivery'];
		$GLOBALS['canContinueGuestCheckout'] = true;
		 
		}
	
	}
	
	// THIS FUNCTION WILL START THE DOWNLOAD PROCESS
	function _downloadproduct(){ global $wpdb, $CORE;
		if(isset($_POST['downloadproduct']) && isset($_POST['pid']) && is_numeric($_POST['pid']) ){		 
			
			// CHECK IF ITS A FREE DOWNLOAD
			if(isset($_POST['free'])){
				if(!isset($_POST['purchased']) && get_post_meta($_POST['pid'],'type',true) == "1" && get_post_meta($_POST['pid'],'price',true) > 0){
				die("no access to this download");
				}
			}
			
			// UPDATE DOWNLOAD COUNTER
			update_post_meta($_POST['pid'], 'download_count', get_post_meta($_POST['pid'], 'download_count',true)+1);
			
			// START DOWNLOAD
			$file = get_post_meta($_POST['pid'], 'download_path',true);
			 
			// ASSUME THE USER HAS LINKED TO THE FILE
			if(strpos($file,get_home_url()) !== false){			
				$b = explode("/wp-content/",THEME_PATH);		
				$file = str_replace(get_home_url(),$b[0],$file);			
			}
			ini_set('memory_limit','256M');	
			if(file_exists($file)) {
						header('Content-Description: File Transfer');
						header('Content-Type: application/octet-stream');
						header('Content-Disposition: attachment; filename='.basename($file));
						header('Content-Transfer-Encoding: binary');
						header('Expires: 0');
						header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
						header('Pragma: public');
						header('Content-Length: ' . filesize($file));
						ob_clean();
						flush();
						readfile($file);
						exit;
			}else{
			die("<h1>Download Error</h1><p>The file your looking for has been moved or deleted. Please contact the website owner.</p>");
			}		
		}
	}	
	
	// THIS FUNCTION WILL HANDLE ALL OF THE CURRENCY CONVERSIONS ETC
	function _currency($p){	
 
	// CHECK IF NOT TURNED OFF
	if($GLOBALS['CORE_THEME']['shop_currencydropdown'] != '1'){ return $p; }
	

 
	if(isset($_REQUEST['c']) && isset($GLOBALS['shop_currency'][$_REQUEST['c']])){ 
			
		$_SESSION['currency'] 	= $GLOBALS['shop_currency'][$_REQUEST['c']];	
	
	}elseif(isset($_SESSION['currency']['rate']) && $_SESSION['currency']['rate'] > 0  ){ 
	
	 	// DO NOTHING	
								 
	}elseif(isset($GLOBALS['shop_currency']) && isset($GLOBALS['currency']['code']) ){
	
		$_SESSION['currency'] 	= $GLOBALS['shop_currency'][$GLOBALS['currency']['code']];
	}
 

	// CALCULATE NEW PRICE	
	if(isset($_SESSION['currency']) && isset($_SESSION['currency']['rate']) && $_SESSION['currency']['rate'] > 0 ){	
		
		// STRIP TAGS FROM PRICE JUST ENCASE
		$p = strip_tags($p); 
		
			// 
			if($_SESSION['currency']['code'] == $GLOBALS['CORE_THEME']['currency']['code']){
			
			$thisrate = 1;		
			
			}else{
			
			$thisrate = $_SESSION['currency']['rate'];
			
			}
		 
		if($p > 0){ 
			$p = str_replace(",","",$p);
			$p = ($p/$thisrate); // get the rate against the default curreny	
			$p = round($p,2); 
			
			$seperator = "."; $sep = ","; $digs = 2; 
			if(is_numeric($p)){		
			$p = number_format($p,$digs, $seperator, $sep); 
			}
		} // end if
		
	} // end if
	
	// RESET DISPLAY CURRENCY
	if(isset($_SESSION['currency']['symbol'])){
	$GLOBALS['CORE_THEME']['currency']['symbol'] = $_SESSION['currency']['symbol'];
	}
 
	return $p;
	}
	// CURRENCY CODE
	function _currencycode($c){
		if(isset($_SESSION['currency']) && $GLOBALS['CORE_THEME']['shop_currencydropdown'] == '1'){
			$c = $_SESSION['currency']['code'];
		}
	return $c;
	}
	// DISPLAY LIST
	function _currenylist($showli=true){ global $post, $CORE, $wpdb; $STRING = "";
	
	if($GLOBALS['CORE_THEME']['shop_currencydropdown'] != '1'){ return; }
	 
		if(get_option('users_can_register') != '1'){ $styleextra = " right"; }else{ $styleextra = ""; }
		
		if($showli){ $STRING .= '<li class="nodivider '.$styleextra.'">'; }
		
		$STRING .= '<div class="btn-group"  id="wlt_shop_currency"><div class="btn">';
		
		// SETUP DEFAULTS
		if(!isset($_SESSION['currency']['code']) || (isset($_SESSION['currency']['code']) && $_SESSION['currency']['code'] == "" ) ){ 
		
			$_SESSION['currency']['code'] 	= $GLOBALS['CORE_THEME']['currency']['code']; 
			$_SESSION['currency']['symbol'] = $GLOBALS['CORE_THEME']['currency']['symbol'];  
			$_SESSION['currency']['rate'] = 0; 		
		
		} 
		
		if(isset($_REQUEST['c'])){
		
		$STRING .= ''.$GLOBALS['shop_currency'][$_REQUEST['c']]['code'].' ('.$GLOBALS['shop_currency'][$_REQUEST['c']]['symbol'].')';	
			
		}elseif(isset($_SESSION['currency'])){
		
		$STRING .= ''.$_SESSION['currency']['code'].' ('.$_SESSION['currency']['symbol'].') ';
		
		}else{
		$STRING .= ''.$GLOBALS['shop_currency'][$GLOBALS['CORE_THEME']['shop_defaultcurrency']]['code'].' ('.$GLOBALS['shop_currency'][$GLOBALS['CORE_THEME']['shop_defaultcurrency']]['symbol'].') ';
		}		
		
		$STRING .= '</div>  <div class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></div>';
 
		$STRING .= '<ul class="dropdown-menu">';
		foreach($GLOBALS['shop_currency'] as $v){
		
			if($GLOBALS['shop_currency'][$v['code']]['rate'] == ""){ continue; }
			
			// DETERMINE IF WE NEED TO ADD A SLASH OR A QUESTION
			$pageLink = $CORE->curPageURL();
			if(substr($pageLink,-1) == "/"){
			$pageLink .= "?";
			}else{
			$pageLink .= "&";
			}
			
			
			$STRING .='<li><a href="'.$pageLink.$v['link'].'">'.$v['code'].' ('.$v['symbol'].')</a></li>';
		}
		$STRING .='</ul>
		
		</div>';
		
			
		if($showli){ $STRING .='</li><li>'; }
		
		return $STRING; 
	}
	
	// ADD NEW PAGE SELECTION FOR CHECKOUT IN THE ADMIN
	function _updatepagelist($c){
	unset($c['add']);
	$c['checkout'] = array("name" => "Checkout");
	return $c;
	}
		
	// NEW MENU OPTIONS TO THE GENERAL SETUP TAB
	function _new_admin_tabs($c){
	
	if(  !isset($_POST['tab']) || isset($_POST['tab']) && $_POST['tab'] == "regions" ) { $class1 = " class='active'"; }else{ $class1 = ""; }
	if(  isset($_POST['tab']) && $_POST['tab'] == "basic_shipping" ) { 	$class2 = " class='active'"; }else{ $class2 = ""; }
	if(  isset($_POST['tab']) && $_POST['tab'] == "basic_tax" ) { 		$class3 = " class='active'"; }else{ $class3 = ""; }
	
	return $c."<li".$class1."><a href='#regions' data-toggle='tab'>Regions</a></li>
	<li".$class3."><a href='#basic_tax' data-toggle='tab'>Tax Options</a></li>	
	<li".$class2."><a href='#basic_shipping' data-toggle='tab'>Shipping Options</a></li>";
	}
	

	 


// ADD IN NEW CART JS FILE
function _shop_footer(){ global $CORE; 
echo '<script type="text/javascript" src="'.FRAMREWORK_URI.'js/core.cart.js"></script>';
echo '<!-- REQUIRED:: CUSTOM PRODUCT ATTS --><input type="hidden" name="wlt_shop_custom_data" value="" id="wlt_shop_custom_data" /><input type="hidden" name="wlt_shop_qty_data" value="1" id="wlt_shop_qty_data" /><input type="hidden" name="wlt_shop_required" value="1" id="wlt_shop_required" />';
?>  
<!-- Modal -->
<div id="addedToCart" class="modal fade addcart" tabindex="-1" role="dialog" aria-labelledby="addedToCartLabel" aria-hidden="true">
  <div class="modal-dialog"><div class="modal-content">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
    <h3 id="addedToCartLabel"><?php echo $CORE->_e(array('checkout','11')); ?></h3>
  </div>
  <div class="modal-body">
    <p><?php echo $CORE->_e(array('checkout','12')); ?></p>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true"><?php echo $CORE->_e(array('checkout','13')); ?></button>
    <button class="btn btn-primary" onclick="document.location.href='<?php echo $GLOBALS['CORE_THEME']['links']['checkout']; ?>'"><?php echo $CORE->_e(array('checkout','14')); ?></button>
  </div>
</div>
</div></div>
<?php

}
// HOOK INTO DISPLAY CONTENT
function _shop_defaultdisplay($c){ global $post, $userdata, $CORE, $wpdb; 

	// ADD ON FALLBACK FOR OLDER VERSIONS
	if(strlen($c) < 1){
		return '[IMAGE]
		<div class="caption">
		<h2>[TITLE]</h2>
		<div class="hidden_details">[EXCERPT]</div>              
		<hr />
		<div class="col-xs-12 col-md-5 lead">[price]</div>
		<div class="col-xs-12 col-md-2"> [ADD] </div>
		</div>';
	}
	// RETURN DEFAULT
return $c;
}




function _languagelist($showli=true){  global $post, $CORE, $wpdb; $STRING = ""; $pLink = "";


if($GLOBALS['CORE_THEME']['shop_languagedropdown'] != '1'){ return; }

if(is_home()){
$pLink = get_home_url();
}elseif(is_single()){
$pLink = get_permalink($post->ID);
}elseif(is_category()){
//$category = $wp_query->get_queried_object();
$pLink = get_category_link( $category->cat_ID );
}elseif(isset($post->ID)){
$pLink = get_page_link($post->ID);
}

$flagsarray = array(	
array('name' => "English", "code"=>"en"),
//array('name' => "Afrikaans", "code"=>"af"),
//array('name' => "Albanian", "code"=>"sq"),
array('name' => "Arabic", "code"=>"ar"),
//array('name' => "Armenian", "code"=>"hy"),
//array('name' => "Azerbaijani", "code"=>"az"),
//array('name' => "Basque", "code"=>"eu"),
array('name' => "Belarusian", "code"=>"be"),
array('name' => "Bengali", "code"=>"bn"),
array('name' => "Bosnian", "code"=>"bs"),
array('name' => "Bulgarian", "code"=>"bg"),
//array('name' => "Catalan", "code"=>"ca"),
//array('name' => "Cebuano", "code"=>"ceb"),
array('name' => "Chinese", "code"=>"zh-CHS"),
array('name' => "Croatian", "code"=>"hr"),
array('name' => "Czech", "code"=>"cs"),
array('name' => "Danish", "code"=>"da"),
array('name' => "Dutch", "code"=>"nl"),
//array('name' => "Esperanto", "code"=>"eo"),
//array('name' => "Estonian", "code"=>"et"),
array('name' => "Filipino", "code"=>"tl"),
array('name' => "Finnish", "code"=>"fi"),
array('name' => "French", "code"=>"fr"),
//array('name' => "Galician", "code"=>"gl"),
//array('name' => "Georgian", "code"=>"ka"),
array('name' => "German", "code"=>"de"),
array('name' => "Greek", "code"=>"el"),
//array('name' => "Gujarati", "code"=>"gu"),
//array('name' => "Haitian Creole", "code"=>"ht"),
//array('name' => "Hebrew", "code"=>"iw"),
//array('name' => "Hindi", "code"=>"hi"),
//array('name' => "Hmong", "code"=>"hmn"),
array('name' => "Hungarian", "code"=>"hu"),
//array('name' => "Icelandic", "code"=>"is"),
array('name' => "Indonesian", "code"=>"id"),
//array('name' => "Irish", "code"=>"ga"),
array('name' => "Italian", "code"=>"it"),
array('name' => "Japanese", "code"=>"ja"),
//array('name' => "Javanese", "code"=>"jw"),
//array('name' => "Kannada", "code"=>"kn"),
//array('name' => "Khmer", "code"=>"km"),
array('name' => "Korean", "code"=>"ko"),
//array('name' => "Lao", "code"=>"lo"),
//array('name' => "Latin", "code"=>"la"),
//array('name' => "Latvian", "code"=>"lv"),
//array('name' => "Lithuanian", "code"=>"lt"),
//array('name' => "Macedonian", "code"=>"mk"),
//array('name' => "Malay", "code"=>"ms"),
//array('name' => "Maltese", "code"=>"mt"),
//array('name' => "Marathi", "code"=>"mr"),
array('name' => "Norwegian", "code"=>"no"),
array('name' => "Persian", "code"=>"fa"),
array('name' => "Polish", "code"=>"pl"),
array('name' => "Portuguese", "code"=>"pt"),
array('name' => "Romanian", "code"=>"ro"),
array('name' => "Russian", "code"=>"ru"),
//array('name' => "Serbian", "code"=>"sr"),
//array('name' => "Slovak", "code"=>"sk"),
//array('name' => "Slovenian", "code"=>"sl"),
array('name' => "Spanish", "code"=>"es"),
//array('name' => "Swahili", "code"=>"sw"),
array('name' => "Swedish", "code"=>"sv"),
//array('name' => "Tamil", "code"=>"ta"),
//array('name' => "Telugu", "code"=>"te"),
array('name' => "Thai", "code"=>"th"),
array('name' => "Turkish", "code"=>"tr"),
//array('name' => "Ukrainian", "code"=>"uk"),
//array('name' => "Urdu", "code"=>"ur"),
array('name' => "Vietnamese", "code"=>"vi"),
//array('name' => "Welsh", "code"=>"cy"),
 
);
 
	if(get_option('users_can_register') != '1'){ $styleextra = " right"; }else{ $styleextra = ""; }
	if($showli){ $STRING .= '<li class="nodivider '.$styleextra.'">'; }
	
	$STRING .= '<div class="btn-group"  id="wlt_shop_language">
	<div class="btn"><img src="'.get_template_directory_uri().'/framework/img/lang/en.png" style="margin-right:10px;" alt="english"> English </div> 
	<div class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></div>
 
    
	
	<ul class="dropdown-menu">';
	foreach($flagsarray as $v){
	
	$STRING .='<li><a href="http://www.microsofttranslator.com/bv.aspx?from=&amp;to='.$v['code'].'&amp;a='.$pLink.'">
	<img src="'.get_template_directory_uri().'/framework/img/lang/'.$v['code'].'.png" style="margin-right:10px;" alt="'.$v['name'].'"> '.$v['name'].'</a>
	</li>';	
	
	}
	
	$STRING .= '</ul></div>';
	
	if($showli){ $STRING .='</li>'; }
	return $STRING; 
}








} // END OF SHOPPING CLASS






 




// ADD A NEW CART SHROTCODE

function wlt_shop_new_tags(){echo "<br />[ADD] - Displays the 'add-to' Cart Button";}
function wlt_shop_new_tags1(){echo "<br />[ADDBIG] - Displays the 'add-to' Cart Button";}
add_action('hook_admin_2_tags_search','wlt_shop_new_tags');
add_action('hook_admin_2_tags_listing','wlt_shop_new_tags');
add_action('hook_admin_2_tags_listing','wlt_shop_new_tags1');
// HOOOK INTO THE LISTINF DISPLAY FUNCTION AND CHANGE THE VIDEO SHORTCODE INTO A VIDEO DISPLAY

function wlt_shop_custom_attributes($postID){

global $wpdb, $CORE; $STRING = "";

		// CHECK FOR CUSTOM ATTRIBUTES
		$current_data = get_post_meta($postID,"wlt_productattributes",true);
		$price = get_post_meta($postID,"price",true);
		
		// FALLBACK FOR OLD CART ATTERIBUTES
		$has_already_set = get_post_meta($postID,'has_already_set_attributes',true);
		if($has_already_set == ""){
			$ia = 1; $g = array();
			while($ia < 8){
				$att = get_post_meta($postID,'customlist'.$ia,true);
				if($att != ""){
				// CHECK FOR CUSTOM TITLE
				$old_title = get_option('custom_field'.$ia);
				if(strlen($old_title) > 1){
				$current_data['name'][] 	=  $old_title;
				}else{
				$current_data['name'][] 	=  "Select Value";
				}				
				$current_data['value'][] 	= str_replace(",","\r\n",$att);
				}
			$ia++;
			} // end while		 
		}// end if
	 
	 
		if(is_array($current_data)){ $i=0;  
		 $STRING .= '<div class="productattributebox">';
		 
		$requiredFields = 0;
		foreach($current_data['name'] as $data){ 
		
			// MAKE SURE WE HAVE A VALID TITLE
			if($current_data['name'][$i] !=""){ 		
			$options = explode( PHP_EOL, $current_data['value'][$i] );
			
				
		$STRING .= '<div class="row productattribute clearfix">';
		
		if(strlen($current_data['name'][$i]) > 10){
		$spanA = "col-md-12"; $spanB = "col-md-10";
		}else{		
		$spanA = "col-md-4"; $spanB = "col-md-8";
		}
		
        $STRING .= '<div class="'.$spanA.'"><label>'.$current_data['name'][$i];
				
				if($current_data['required'][$i] == 1){
				$STRING .= ' <span style="color:red;">*</span>';
				}
				$STRING .= '</div>
                <div class="'.$spanB.'">'; 
				
				// CHECK IF THIS VALUE IS REQUIRED, IF SO DISABLE THE BUY NOW BUTTON
				if($current_data['required'][$i] == 1){
				
				
				echo "				
				<script>				
				jQuery(document).ready(function(){ 								
					jQuery('#selection_box_".$i."').change(function() {	
					
						jQuery('#wlt_shop_required').val(1);
						
						// CHECK IF THERE ARE ANY MORE REQUIRED FIELDS
						var has_more_required = jQuery('#reqq".($requiredFields+1)."').val();						 				 					
						if(typeof has_more_required != 'undefined'){
						
						}else{
						jQuery('#single_addcart_btn').removeAttr('disabled', 'disabled');					 					
						}						
						
					});
					jQuery('#single_addcart_btn').attr('disabled', 'disabled');
					jQuery('#single_addcart_btn').click(function(){ if(jQuery('#selection_box_".$i."').val() == '0'){ alert('".str_replace("%a",$current_data['name'][$i],$CORE->_e(array('checkout','19')))."'); jQuery('#wlt_shop_required').val(0); return false; } });				
				});				 
				</script>
				";
				 
				echo "<input type='hidden' name='reqq' id='reqq".$requiredFields."' value='".$requiredFields."'>";
				 
				
				$requiredFields++;
				
				}			
			 
				// DISPLAY COLOR OPTIONS
				if(isset($current_data['color'][$i]) && $current_data['color'][$i] == "1"){
				
					$STRING .= '<ul class="clearfix" id="color_to_pick_list">';
					$g =0;
					foreach($options as $option){
					$v = explode("[",$option); if(isset($v[1])){ $_t = trim($v[0]); $_v = trim(str_replace("]","",$v[1])); }else{ $_t = trim($v[0]); $_v = trim($v[0]); }
					
					$STRING .= '<li class="red" id="li'.$g.'">
					<a class="color_pick" style="background: '.$_v.';" title="'.$_t.'" onclick="removeselectedred();setselectedred(\'#li'.$g.'\');HandleCustomSelection(\''.$_t.'\',\''.$current_data['name'][$i].'\',\'custom_field_id'.$i.'\',\''.$price.'\');"></a>
					</li>';
					$g++;
					}
					$STRING .= '</ul>
					
					<script> 
					function removeselectedred(){					
						jQuery( "#color_to_pick_list li" ).each(function() {
						  jQuery(this).removeClass( "selected" );
						});
					}
					function setselectedred(c){
					jQuery(c).addClass( "selected" );
					jQuery("#single_addcart_btn").removeAttr("disabled", "disabled");
					}
					</script>
					
					';	 
				
				// DISPLAY SELECTION BOX ITEMS
				}else{		
					
					$STRING .= "<input type='hidden' name='wlt_listingpage_default_price' id='wlt_listingpage_default_price' value='".$price."' />";
					$STRING .= "<select onchange=\"HandleCustomSelection(this.value,'".$current_data['name'][$i]."','custom_field_id".$i."','".$price."')\" id='selection_box_".$i."' class='form-control'>"; 
					$STRING .= '<option value="0"></option>';
					foreach($options as $option){ 
					$v = explode("[",$option); if(isset($v[1])){ $_t = $v[0]; $_v = str_replace("]","",$v[1]); }else{ $_t = $v[0]; $_v = $v[0]; }
					$STRING .= '<option value="'.trim($_v).'">'.trim($_t).'</option>'; }
					$STRING .= '</select>';
				}
		
		// ADD IN HIDDEN FIELD
		$STRING .= '<input type="hidden" id="custom_field_id'.$i.'" /> ';	
		
		 $STRING .= ' </div>
            </div><div class="clearfix"></div>';
			
		}  $i++; }
		
		$STRING .= '</div>'; // end box
		 } 
		
		return $STRING;
}
function wlt_shop_display($c){ global $wpdb, $post, $userdata, $CORE; $STRING = ""; 

// ITEMS THAT MAKE UP THE ADD TO CART BUTTON INCLUDE
// PHP SESSION ID
// WEBSITE URL
// PRODUCT DATA id|price
// ERROR TEXT
// OK TEXT
// OK LINK
 
$price = get_post_meta($post->ID,"price",true);
$qty = get_post_meta($post->ID,'qty',true);

if(is_numeric($price) && $price != "" && ( $qty == "" || $qty > 0) ){

	// CHECK FOR ATTRIBUTES
	$current_data = get_post_meta($post->ID,"wlt_productattributes",true);
	 
		if(is_array($current_data) && strlen($current_data['name'][0]) > 1){
	
			$STRING = "<a href='".get_permalink($post->ID)."' class='btn btn-sm btn-primary'>".$CORE->_e(array('checkout','16'))."</a>"; 		
		
		}else{
		
			$CORE_btn_add = "addProduct('".session_id()."', '".get_home_url()."/', '".$post->ID."|".str_replace(",","",$price)."','".$GLOBALS['CORE_THEME']['links']['checkout']."')";	
		
			$STRING = "<a href='#addedToCart' data-toggle='modal' class='btn btn-sm btn-primary' onclick=\"".$CORE_btn_add.";\">".$CORE->_e(array('checkout','16'))."</a>"; 
		
			
		}
	$STRING = hook_addcart_small($STRING);
	
}
 
$STRING = str_replace("[ADD]",$STRING,$c);

 

 
if(isset($GLOBALS['flag-single']) && (strpos($STRING, "[ADDBIG]") !== false) ){

		// DEFAULTS
		$SINGLE_ADDCART_BUTTON = ""; $canContinue = true; $product_type = get_post_meta($post->ID,'type',true);
		
		// CHANGE FOR DEMO
		if(defined('WLT_DEMOMODE') && $product_type == 2){ $product_type =1; }
		
		// CHECK QTY AVAILABLE
		$qty = get_post_meta($post->ID,'qty',true);
		if(is_numeric($qty) && $qty < 1){
		$msg = get_post_meta($post->ID,'stock_outofmsg',true);
		if($msg == ""){ $msg = $CORE->_e(array('checkout','48')); }
		$SINGLE_ADDCART_BUTTON .=  "<div class='outofstockmessage alert alert-warning' style='text-align:center;font-weight:bold;'>".$msg."</div>";
		$canContinue = false;
		}
		
		// CHECK WE CAN CONTINUE;
 		if($canContinue){
		
			$SINGLE_ADDCART_BUTTON .= '<div class="clearfix"></div><div id="wlt_shop_basket"> ';
			//<div class="block-title"><h3><span>'.$CORE->_e(array('single','16')).'</span></h3></div>';
			$SINGLE_ADDCART_BUTTON .= wlt_shop_custom_attributes($post->ID);
			$SINGLE_ADDCART_BUTTON .= '<div class="basket_content"><div class="row-fluid">';
				
			// CHECK FOR MIN.ORDER AMOUNTS
			$qty = get_post_meta($post->ID,'qty',true);
			$qty_min = get_post_meta($post->ID,'qty_min',true);
			if(is_numeric($qty_min) && $qty_min > 1){
				$SINGLE_ADDCART_BUTTON .= "			
				<div class='row-fluid clearfix'>
				<div class='col-md-7'>".$CORE->_e(array('checkout','20'))." ".$qty_min." ".$CORE->_e(array('checkout','21')).".</div>
				<div class='col-md-5' style='text-align:right'>				
				 <div class='input-prepend'>
				  <span class='add-on'>".$CORE->_e(array('checkout','3'))."</span>
				  <input type='text' style='width:30px;' value='".$qty_min."' onchange='changeqtyval(this.value)'>
				</div>
				
				 </div>
				</div>
				<hr />
				<script>
				function changeqtyval(c){
				jQuery('#wlt_shop_qty_data').val(c);
				}
				jQuery(document).ready(function(){  jQuery('#wlt_shop_qty_data').val(".$qty_min."); });
				</script>
				<div class='clearfix'></div>";
				
			}elseif($qty > 0){
			
			$SINGLE_ADDCART_BUTTON .= "			
				<div class='row-fluid clearfix'>
				<div class='col-md-7'> </div>
				<div class='col-md-5' style='text-align:right'>				
				 <div class='input-prepend'>
				  <span class='add-on'>".$CORE->_e(array('checkout','3'))."</span>
				  <input type='text' style='width:30px;' value='".$qty_min."' onchange='changeqtyval(this.value)'>
				</div>
				
				 </div>
				</div>
				<hr />
				<script>
				function changeqtyval(c){
				var max_amount = ".$qty .";
				if(c < max_amount){
					jQuery('#wlt_shop_qty_data').val(c);
				}else{
					jQuery('#wlt_shop_qty_data').val(max_amount);
				}
				}
				jQuery('#wlt_shop_qty_data').val(".$qty_min.");
				</script>
				<div class='clearfix'></div>";
			}
			
			
			// LEFT SIDE AREA
			$SINGLE_ADDCART_BUTTON .= '<div class="col-md-5">';
			if($price > 0){		
		   		$SINGLE_ADDCART_BUTTON .= '<div class="pricettag">'.hook_price('<span id="wlt_listingpage_pricetag">'.$price.'</span>').'</div>';
		   	}elseif($price == 0 && $product_type == "1"){
					$download_count = get_post_meta($post->ID,'download_count',true); if($download_count == ""){ $download_count =0;} 
					$SINGLE_ADDCART_BUTTON .= '<div class="downloadstag">'.$download_count.' '.$CORE->_e(array('checkout','22')).' </div>';
			}
		    $SINGLE_ADDCART_BUTTON .= '</div>';
			
			
			// RIGHT SIDE AREA
			$SINGLE_ADDCART_BUTTON .= '<div class="col-md-7"><div class="wlt_basket_actions">';
			
			// SWITCH PRODUCT TYPE FOR DISPLAY
			switch($product_type){
			
				case "1": { // DOWNLOAD PRODUCT
				
					if($price == 0){ // download button for free downloads	
					 
						if($userdata->ID){
						$SINGLE_ADDCART_BUTTON .= '<form method="post" action="'.get_permalink($post->ID).'" style="margin:0px;">
						<input type="hidden" name="pid" value="'.$post->ID.'" />
						<input type="hidden" name="free" value="1" />
						<input type="hidden" name="downloadproduct" value="1" />';
						$SINGLE_ADDCART_BUTTON .= "<button type='submit' class='btn btn-primary' onclick=\"".$CORE_btn_add.";\">".$CORE->_e(array('checkout','18'))."</button>";
						$SINGLE_ADDCART_BUTTON .= '</form>'; 
						}else{
						$SINGLE_ADDCART_BUTTON .= "<button type='button' class='btn btn-primary' onclick=\"alert('Members Only. Please login to download.');\">".$CORE->_e(array('checkout','18'))."</button>";
						}
					}else{					
						if(is_numeric($price) && $price != "" && $price > 0){	 // add cart button for products with a price				
						$CORE_btn_add = "addProduct('".session_id()."', '".get_home_url()."/', '".$post->ID."|".str_replace(",","",$price)."','".$GLOBALS['CORE_THEME']['links']['checkout']."')";				
						$SINGLE_ADDCART_BUTTON .= "<a href='#addedToCart' data-toggle='modal' id='single_addcart_btn' class='btn btn-sm btn-primary' onclick=\"".$CORE_btn_add.";\">".$CORE->_e(array('checkout','16'))."</a>"; 
						$SINGLE_ADDCART_BUTTON = hook_addcart_big($SINGLE_ADDCART_BUTTON);				
						}					
					}
				
				} break;
				case "2": { // AFFILIATE PRODUCT
				
					$SINGLE_ADDCART_BUTTON .= hook_addcart_big("<a href='".get_home_url()."/out/".$post->ID."/buy_link/' id='single_addcart_btn' target='_blank' rel='nofollow' class='btn btn-primary'>".$CORE->_e(array('checkout','16'))."</a>"); 
					
				} break;			
				default: { // NORMAL PRODUCT
				
					if(is_numeric($price) && $price != "" && $price > 0){	 // add cart button for products with a price				
					$CORE_btn_add = "addProduct('".session_id()."', '".get_home_url()."/', '".$post->ID."|".str_replace(",","",$price)."','".$GLOBALS['CORE_THEME']['links']['checkout']."')";				
					$SINGLE_ADDCART_BUTTON .= "<button type='button' id='single_addcart_btn' class='btn btn-sm btn-primary'>".$CORE->_e(array('checkout','16'))."</button>"; 
					
					$SINGLE_ADDCART_BUTTON .= "<script>				
					jQuery(document).ready(function(){ 								
						jQuery('#single_addcart_btn').click(function() {					
							if(jQuery('#wlt_shop_required').val() == 1){
								".$CORE_btn_add."  
								jQuery('#addedToCart').modal('show'); 
							}
						});									
					});				 
					</script>";
					 
					
					$SINGLE_ADDCART_BUTTON = hook_addcart_big($SINGLE_ADDCART_BUTTON);				
					}
				
				} break	;			
			}
			 
			// END BOX
			$SINGLE_ADDCART_BUTTON .= '</div></div></div>';                      
			$SINGLE_ADDCART_BUTTON .= '<div class="clearfix"></div></div></div>'; 	
			
		} // end of can continue;
			
		$STRING = str_replace("[ADDBIG]",hook_tag_addbig($SINGLE_ADDCART_BUTTON),$c);	
			
		}
 
return $STRING;
 
}
add_action('hook_content_listing','wlt_shop_display');
add_action('hook_content_single_listing','wlt_shop_display');

function wlt_shop_shortcode_add($c){ global $wpdb, $post, $CORE; $STRING = ""; 
 
// CHECK HAS A VALID PRICE
$price = get_post_meta($post->ID,"price",true);
if(is_numeric($price) && $price != ""){

	// CHECK FOR CUSTOM ATTRIBUTES
	$type =		 get_post_meta($post->ID,"type",true);
	$current_data 	= get_post_meta($post->ID,"wlt_productattributes",true);
	if( ( is_array($current_data) && !empty($current_data) && !isset($GLOBALS['flag-single']) ) || $type == 2 ){
	
	$STRING = "<a href='".get_permalink($post->ID)."' class='btn btn-sm btn-primary'>".$CORE->_e(array('checkout','16'))."</a>"; 
	
	}else{
	
	$CORE_btn_add = "addProduct('".session_id()."', '".get_home_url()."/', '".$post->ID."|".str_replace(",","",$price)."','".$GLOBALS['CORE_THEME']['links']['checkout']."');";	
	
	$STRING = "<a href='#addedToCart' data-toggle='modal' class='btn btn-sm btn-primary' onclick=\"".$CORE_btn_add.";\">".$CORE->_e(array('checkout','16'))."</a>"; 
	
	}
		
	$STRING = hook_addcart_small($STRING);
	
}
 
return $STRING;

}
add_shortcode( 'ADD', 'wlt_shop_shortcode_add' );

// ADD IN A NEW PAGE OPTION FOR THE CHECKOUT
function wlt_shop_new_page_list(){ 

global $wpdb;

$core_admin_values = get_option("core_admin_values"); ?>
<style>#addlisting_page_select { display:none; }</style>
<!------------ FIELD -------------->          
<div class="form-row control-group row-fluid">
	<label class="control-label span4" for="normal-field">Checkout Page =</label>
    <div class="controls span7">
 
    <select data-placeholder="Choose a page..." class="chzn-select" name="admin_values[links][checkout]">
    <option></option>
  <?php 
  $pages = get_pages(); 
  foreach ( $pages as $page ) {
  
  	$link = get_page_link( $page->ID );
  	$option = '<option value="'. $link.'"';
	if($core_admin_values['links']['checkout'] == $link){
	$option .= " selected=selected ";
	} 
	$option .= '>';
	$option .= $page->post_title;
	$option .= '</option>';
	echo $option;
  }
 ?>
    </select>
    	 
    </div>
</div>
<!------------ END FIELD -------------->  

<?php }

add_action('hook_admin_1_tab1_left','wlt_shop_new_page_list');







/* =============================================================================
	  CHECKOUT WIDGET
	========================================================================== */
	
 class wlt_shop_checkout_widget extends WP_Widget {

    function wlt_shop_checkout_widget() {
        // widget actual processes		
		$opts = array(
			'classname' => 'wlt_shop_checkout',
			'description' => 'This widget will add a checkout item to your sidebar.',
		);
		parent::__construct( 'wlt_shop_checkout', 'Shopping Basket' , $opts );
		
    }

    function form($instance) {
   
		$instance = wp_parse_args( $instance, $defaults );
		
	 ?>
     
 	<p><b>Title</b></p>
	<input class="widefat" type="text" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" />
     
	 <?php

    }

	function update( $new, $old )
	{	
	
		$clean = $old;
		
		$clean['title'] = isset( $new['title'] ) ? strip_tags( esc_html( $new['title'] ) ) : '';
		
		return $clean;
	}

    function widget($args, $instance) {

	global $CORE, $post, $CORE; $STRING = ""; @extract($args); $GLOBALS['flasg-shoppingbasket'] = 1;
	
	// HIDE ON CHECKOUT PAGE
	//if(isset($GLOBALS['flag-checkout']) || !isset($GLOBALS['flag-single']) ){ return; }
	
	//if(isset($GLOBALS['flag-single']) && $post->post_type != THEME_TAXONOMY."_type"){ return; }
	// BUILD WIDGET OUTPUT
	echo "<div id='wlt_shop_basket'>".$before_widget.$before_title.$instance['title'].$after_title; 
	// GET CART DATA
	$cart_data = $this->GETCART(true);      
	if($cart_data['qty'] == ""){ $cart_data['qty'] =0; }
	
 
    ?>
    <div class="wlt_basket">
    <p><b id="wlt_cart_qty"><?php echo $cart_data['qty']; ?></b> <?php echo $CORE->_e(array('checkout','15')); ?> - <b><?php echo $GLOBALS['CORE_THEME']['currency']['symbol']; ?><span id="wlt_cart_total"><?php echo $cart_data['total']; ?></span></b>
    </div>
    
    <?php 
	// CHECK IF WE SHOULD DISPLAY THE PRODUCTS ADDED
	if($cart_data['qty'] > 0){ ?>
    <hr />  
    <div class="wlt_basket_list" id="wlt_basket_list">
    <?php $counter=0; foreach($cart_data['items'] as $key=> $inner_item){  foreach($inner_item as $item){  ?>
    <div class="wlt_basket_item clearfix" id="basket_row_<?php echo $counter; ?>">
    <?php echo $item['image']; ?>
        <div class="data">
        <a href="<?php echo $item['link']; ?>"><?php echo $item['name']; ?></a>
        <div class="clearfix"></div>
        <small><a href="javascript:void(0);" onclick="jQuery('#basket_row_<?php echo $counter; ?>').hide();<?php echo $this->REMOVEITEM($key, $item['innerID'],$item['amount']); ?>"><?php echo $CORE->_e(array('checkout','5')); ?></a></small>
        </div>
    </div>
    <?php $counter++; } } ?>   
    <div class="clearfix"></div> 
    </div>
    <hr />    
    <div class="wlt_basket_actions">    
    <a  class='btn btn-primary' href='<?php echo $GLOBALS['CORE_THEME']['links']['checkout']; ?>'><?php echo $CORE->_e(array('checkout','14')); ?></a>	
    </div>    
    <?php } // END DISPLAY OF PRODUCTS		
	
	// FINISH WIDGET OUTPUT
	echo $after_widget."</div>"; 
 
    }
}
// REGISTER CORE WIDGETS
//register_widget( 'wlt_shop_checkout_widget' );







































 

function wlt_cart_savedata(){
	// CHECK IF WE ARE SAVING THIS
	if(isset($_POST['wlt_productattributes'])){
	update_post_meta($_POST['post_ID'],"wlt_productattributes",$_POST['wlt_productattributes']);	
 	update_post_meta($_POST['post_ID'],"wlt_productdiscounts",$_POST['wlt_productdiscounts']);	 	 
	}
}

// LOAD ALL PREMIUMPRESS ADMIN EDITING DATA	
add_action('save_post', 'wlt_cart_savedata', 1, 2);


// TURN OFF TOOLBOX FOR THIS THEME
function BlankMeShopToolbox($c){return "";}
add_action('hook_single_toolbox','BlankMeShopToolbox');

// ADD IN ADMIN TEST OPTIONS

function admin_test_checkout(){ global $userdata; if(user_can($userdata->ID, 'administrator')){  ?>

<form style="width:200px; float:left;" method="post" action="<?php echo $GLOBALS['CORE_THEME']['links']['callback']; ?>">
<input type="hidden" name="mc_gross" value="<?php echo $GLOBALS['global_cart_data']['total'] ; ?>" />
<input type="hidden" name="custom" value="CART-<?php echo $GLOBALS['global_cart_data']['session'] ; ?>" />
<input type="hidden" name="payment_status" value="Completed" />
<input type="hidden" name="c_currency" value="<?php echo $GLOBALS['CORE_THEME']['currency']['code']; ?>" />
<input type="hidden" name="txn_id" value="123567<?php echo time(); ?>" />
<input type="hidden" name="payer_email" value="<?php echo $userdata->user_email; ?>" />
<?php

 
if(isset($GLOBALS['global_cart_data']['items']) && is_array($GLOBALS['global_cart_data']['items'])){
		// BUILD PAYPAL CART DATA
		$i=1; 
		foreach($GLOBALS['global_cart_data']['items'] as $key=>$inneritem){
			foreach($inneritem as $item){		
			
			$name = $item['name'];
			if(strlen($item['custom']) > 1){ $name .= "-".$item['custom']; }	 
			$gatewaycode .='<input type="hidden" name="item_name_'.$i.'" value="'.trim(strip_tags($name)).'">
			<input type="hidden" name="amount_'.$i.'" value="'.trim($item['amount']).'">
			<input type="hidden" name="quantity_'.$i.'" value="'.$item['qty'].'">';
			$i++;
			}			
		}	
	 
	}else{
	 
	$gatewaycode .= '<input type="hidden" name="item_name" value="'.strip_tags($GLOBALS['description']).'">';
	 
	}
	echo $gatewaycode;
?>
 
<button class="btn" type="submit">Admin Test Callback</button>
</form> 

<?php } }
add_action('hook_checkout_after_paymentoptions','admin_test_checkout');








 


function basic_tax_calculate($c){

global $wpdb, $userdata, $CORE; 
$core_admin_values 				= get_option("core_admin_values");
$current_country_tax_array 		= get_option('wlt_country_tax_price_array');
$current_wlt_tax_exemp_array 	= get_option('wlt_tax_exemp_array');
$core_admin_values 				= get_option("core_admin_values");
$current_country_ship_array 	= get_option('wlt_country_ship_price_array'); 
//update_option('wlt_country_ship_price_array','');
$tax_exempt_product_count = 0; // SET NUMBER OF PRODUCTS EXEMPTY FROM TAX

// BACKUP OF CURRENT SHIP TOTAL
$OLD_SUBTITLE = $c['subtotal'];

// CHECK WE HAVE A POSiTIVE QTY
if($c['qty'] < 1){ return $c; }

// GET THE USERS DELIVERY COUNTRY
$delivery_country = get_user_meta($userdata->ID,"billing_country",true);
if(isset($_POST['delivery']['billing_country']) && strlen($_POST['delivery']['billing_country']) > 1){
$delivery_country = $_POST['delivery']['billing_country'];
}
$delivery_state = get_user_meta($userdata->ID,"billing_state",true);
if(isset($_POST['delivery']['billing_state']) && strlen($_POST['delivery']['billing_state']) > 1){
$delivery_state = $_POST['delivery']['billing_state'];
}
if(isset($_GET['guestcheckout']) && isset($_POST['delivery']['billing_method'])){ 
$delivery_method = $_POST['delivery']['billing_method'];
}else{
$delivery_method = get_user_meta($userdata->ID, "billing_method",true);  
}
 
if($delivery_method == ""){ $delivery_method = "default"; }else{

	if(isset($GLOBALS['CORE_THEME']['cart_method_list']) && in_array($delivery_method, $GLOBALS['CORE_THEME']['cart_method_list']) ){	
	}else{
	$delivery_method = "default";
	}
}
 
//3. TAX EXEMPTIONS
if(is_array($current_wlt_tax_exemp_array) && !empty($current_wlt_tax_exemp_array) ){
	//  WE HAVE THE CURRENT COUNTRY SO LOOP THROUGH AND SEE IF THE COUNTRY IS THERE
	foreach($current_wlt_tax_exemp_array as $key=>$taxm){
		foreach($taxm['country'] as $cc){		
			if( (isset($delivery_country) && $cc == $delivery_country ) || ( $cc == "1" ) ){
				// FOUND A COUNTRY MATCH, LETS CHECK IF WE HAVE A MATCHING CUSTOM FIELD				
				foreach($c['items'] as $postid=>$post_data){				 
					if(get_post_meta($postid,$key,true) == $taxm['value']){
					$tax_exempt_product_count++;
					}// end if				
				}			
			}// end if
		}// enf foreach
	}// end foreach
}// end if

// SINCE EACH PRODUCT HAS ITS OWN TAX CLASS, WE NEED TO LOOP ALL PRODUCTS TO CHECK
if(isset($GLOBALS['flag-checkout'])){
foreach($c['items'] as $postid => $post_data){
	foreach($post_data as $product){
	 
		//1. FLAT RATE SHIPPING AND TAXES
		if(isset($core_admin_values['basic_tax']) && is_numeric($core_admin_values['basic_tax']['flatrate']) && !isset($flatratetax_isset) ){	 //&& get_post_meta($postid,'tax_required',true) != "0" 
			$ff = ($tax_exempt_product_count/$product['qty'])*100;	
			$c['tax'] += ($core_admin_values['basic_tax']['flatrate']-$ff); $flatratetax_isset = true;
		}
		if(isset($core_admin_values['basic_tax']) && is_numeric($core_admin_values['basic_tax']['flatrate_percent']) && !isset($flatratetax_isset)  ){	 // && get_post_meta($postid,'tax_required',true) != "0" 
			$ff = ($tax_exempt_product_count/$product['qty'])*100; //$flatratetax_isset = true;
			$c['tax'] += (($product['qty']*$product['amount'])*$core_admin_values['basic_tax']['flatrate_percent']/100);
		}
		if(isset($core_admin_values['basic_shipping']) && is_numeric($core_admin_values['basic_shipping']['flatrate']) && !isset($flatrateship_isset) && get_post_meta($postid,'ship_required',true) != "0"   ){ // 
			$c['shipping'] += $core_admin_values['basic_shipping']['flatrate']; $flatrateship_isset = true;
		}
		if(isset($core_admin_values['basic_shipping']) && is_numeric($core_admin_values['basic_shipping']['flatrate_percent']) && !isset($flatrateship_isset) && get_post_meta($postid,'ship_required',true) != "0" ){ // 
			$flatrateship_isset = true;
			$c['shipping'] += (($product['qty']*$product['amount'])*$core_admin_values['basic_shipping']['flatrate_percent']/100);
		}	
	}// end product loop	
}// end items loop
}

  
//2. COUNTRY SHIPPING
if(isset($core_admin_values['basic_country_shipping']) && $core_admin_values['basic_country_shipping'] == '1'){
 
	// LOOP THROUGH ALL THE CART ITEMS AND ADD ON THE TAX
	foreach($c['items'] as $key=>$shippable_items){ foreach($shippable_items as $ship_item){
		
		// SET FLAGS
		$country_shipping_set 	= false;
		$state_shipping_set 	= false;

		// MAKE SURE THE ITEM IS SET TO BE TAXABLE		
		$ship_required = get_post_meta($key,'ship_required',true);		
		if($ship_required == "0"){ continue; }		
	
		// GET THE SHPPING WEIGHT TYPE (LIGHT/HEAVY ETC)
		$weight_type = get_post_meta($key,'weight_type',true);
		if($weight_type == ""){ $weight_type = 0; }
	 	  
		// LOOP THROUGH ALL REGIONS AND SEE IF WE HAVE A VALUE FOR THIS DELIVERY COUNTRY		 
		if(is_array($core_admin_values['regions'])){ $i = -1; 
		
			while($i <= 20 ){  
			
				if($core_admin_values['regions']['name'][$i] !=""){  				
					
					// REGION NAME
					$region_name = $core_admin_values['regions']['name'][$i];	
					
		 			// COUNTRY CHECKOUT
					if(is_array($core_admin_values['regions']['country'][$i]) && in_array($delivery_country, $core_admin_values['regions']['country'][$i])) { 
					
						// check if we have a value for this country			 			 
						if(isset($current_country_ship_array[$delivery_method][$region_name][$weight_type]) && !$country_shipping_set ){
							// add on new price					 
							$c['shipping'] += $current_country_ship_array[$delivery_method][$region_name][$weight_type]*$ship_item['qty'];
							$country_shipping_set = true;
						} // end if
							
					}// end if for country
					
						
					// STATE CHECKOUT 
					if(is_array($core_admin_values['regions']['state'][$i]) && in_array($delivery_state, $core_admin_values['regions']['state'][$i]) ) { 				 			 
												
						// check if we have a value for this country			 			 
						if(isset($current_country_ship_array[$delivery_method][$region_name][$weight_type])  && !$state_shipping_set  ){
							// add on new price				 
							$c['shipping'] += $current_country_ship_array[$delivery_method][$region_name][$weight_type]*$ship_item['qty'];
							$state_shipping_set = true;
						} // end if				
					}// end if for country 
		
				} 
		
			$i++;
			} 
		
		}// end loop regions
		
		
	} } // end foreach
}

//2. COUNTRY TAX
if(isset($core_admin_values['basic_country_tax_tax']) && $core_admin_values['basic_country_tax_tax'] == '1'){

	// LOOP THROUGH ALL THE CART ITEMS AND ADD ON THE TAX
	foreach($c['items'] as $key=>$taxable_items){ foreach($taxable_items as $taxable_item){
			
		// MAKE SURE THE ITEM IS SET TO BE TAXABLE		
		$tax_required = get_post_meta($key,'tax_required',true);
		if($tax_required == "0"){ continue; }
  		
		
		// LOOP THROUGH ALL REGIONS AND SEE IF WE HAVE A VALUE FOR THIS DELIVERY COUNTRY		 
		if(is_array($core_admin_values['regions'])){ $i=-1; while($i <= count($core_admin_values['regions']['state'])){  $i++;
		
		if($core_admin_values['regions']['name'][$i] !=""){ 
		  
			if( (!empty($core_admin_values['regions']['country'][$i]) && in_array($delivery_country, $core_admin_values['regions']['country'][$i]) ) 
			|| (!empty($core_admin_values['regions']['state'][$i]) && in_array($delivery_state, $core_admin_values['regions']['state'][$i]) ) ) { // COUNTRY OR STATE CHECKOUT	
							 			 
				$region_name = $core_admin_values['regions']['name'][$i]; 
				 
				// CHECK TAX EXEMPTION
				if(isset($current_country_tax_array[$region_name]['excemption']) && strlen($current_country_tax_array[$region_name]['excemption']) > 0 ){
					$val = get_post_meta($key,$current_country_tax_array[$region_name]['excemption'],true);			 
					if($val != ""){ continue; }
				}		
				
				// PRICE TAX
				if(!isset($taxisset) && isset($current_country_tax_array[$region_name]['price']) && is_numeric($current_country_tax_array[$region_name]['price']) && $current_country_tax_array[$region_name]['price'] != 0 ){ 
							  
						$ff = $current_country_tax_array[$region_name]['price']*$taxable_item['qty'];				
						$c['tax'] += $ff;	
						//$taxisset = true;
					
				// PERCENTAGE TAX
				}elseif(!isset($taxisset) && isset($current_country_tax_array[$region_name]['percent']) &&  is_numeric($current_country_tax_array[$region_name]['percent']) && $current_country_tax_array[$region_name]['percent'] != 0 ){
					 
					$taxA = $taxable_item['amount']*$taxable_item['qty']/100*$current_country_tax_array[$region_name]['percent'];
					$taxA += $c['shipping']/100*$current_country_tax_array[$region_name]['percent'];
					$c['tax'] +=  number_format($taxA, 2);
					//$taxisset = true;
			 
				} // end if
				
					
			}// end if for country	 
		
		
		}   }  }// end loop regions
		
		
			
	} } // end foreach
	
}
 
//4. CHECK FOR PER PRODUCT TAX
if(isset($core_admin_values['per_product_tax']['enable']) && $core_admin_values['per_product_tax']['enable'] == '1' && isset($core_admin_values['per_product_tax']['key']) ){ 
	// LOOP THROUGH ALL THE CART ITEMS AND ADD ON THE TAX
	foreach($c['items'] as $key=>$taxable_items){ foreach($taxable_items as $taxable_item){
		
		// MAKE SURE THE ITEM IS SET TO BE TAXABLE		
		$tax_required = get_post_meta($key,'tax_required',true);
		if($tax_required == "0"){ continue; }
		// NOW WORK OUT TAX
		$tax_value = get_post_meta($key,$core_admin_values['per_product_tax']['key'],true);
		if(is_numeric($tax_value) && $tax_value !="" && $tax_value > 0){
			$c['tax'] +=  number_format(($taxable_item['amount']*$taxable_item['qty'])/100*$tax_value, 2);	
		 	 
		}	
	} }
}
 
//5. WEIGHT BASED SHIPPING
if(isset($core_admin_values['weightship']) && is_array($core_admin_values['weightship']) && !empty($core_admin_values['weightship'])){ 
	$wi=0;  $completed_items = array();
	$loopcount = count($core_admin_values['weightship']['region']);
	 
	while($wi < $loopcount){ 
	
		if($core_admin_values['weightship']['pricea'][$wi] == ""){ $wi++; continue; }
		
		 //echo $core_admin_values['weightship']['pricea'][$wi]."<--(".$delivery_country.")<br>";
		// LOOP THROUGH ALL THE CART ITEMS AND ADD ON SHIPPING
		foreach($c['items'] as $key=>$shippable_items){  foreach($shippable_items as $shippable_item){
		
			// SKIP IF ALREADY ADDED
			if(in_array($key, $completed_items)){ continue; }
	 
			// MAKE SURE THE ITEM IS SET TO BE TAXABLE		
			$ship_required = get_post_meta($key,'ship_required',true);		
			if($ship_required == "0"){ continue; }
			
			// GET WEIGHT
			$weight = $c['weight'];
			 
			if($weight >= $core_admin_values['weightship']['pricea'][$wi] && $weight <= $core_admin_values['weightship']['priceb'][$wi]){
			
			//echo $weight." (".$key.")<--<br>";
				// NOW LOOP THROUGH ALL REGIONS TO SEE IF WE SHOULD ADD THIS WEIGHT TO THE BASKET
		 	 	if($core_admin_values['weightship']['region'][$wi] == ""){				
					// ADD-ON SHIP BECAUSE NO REGION WAS SET
					$c['shipping'] += $core_admin_values['weightship']['pricec'][$wi];
					$completed_items[$key] = $key;	
				
				}else{
				
					// LOOP REGIONS AND CHECK AGINST DELIVERY COUNTRY
					if(is_array($core_admin_values['regions'])){ 
						$i= 0; 
						//print_r($core_admin_values['regions']);
						while($i <= count($core_admin_values['regions']['name'])){  
						
						//echo $i."".$core_admin_values['regions']['name'][$i]."<br>";
							if($core_admin_values['regions']['name'][$i] ==""){ $i++; continue; }
								
								//echo print_r($core_admin_values['regions']['country'][$i])." (".$delivery_country.")<br>";
								// NOW CHECK IF CURRENT DELIVERY COUNTRY/STATE IS FOUND IN THIS REGION
								if( (!empty($core_admin_values['regions']['country'][$i]) && in_array($delivery_country, $core_admin_values['regions']['country'][$i]) ) 
			|| (!empty($core_admin_values['regions']['state'][$i]) && in_array($delivery_state, $core_admin_values['regions']['state'][$i]) ) ) {
							 	
									if($core_admin_values['weightship']['region'][$wi]	== $core_admin_values['regions']['name'][$i]){
									// ADD-ON SHIP BECAUSE NO REGION WAS SET
									$c['shipping'] += $core_admin_values['weightship']['pricec'][$wi];
									$completed_items[$key] = $key;
									}
								
								}else{
								 //echo "no found";
								}
								
								$i++;
							
						} // END WHILE
					}// END IF	
					
				}// END ELSE				
				
			}// end if
			 
		 } // end foreach
	$wi++; 
	}// end while
}}
 


//6. FREE SHIPPING
if(isset($core_admin_values['basic_free_shipping']) && $core_admin_values['basic_free_shipping'] == '1'){  $current_free_shipping_array = get_option('wlt_free_shipping_array'); 

	// FALLBACK IF NOT ARRAY
	if(!is_array($current_free_shipping_array)){ $current_free_shipping_array = array(); }	
	
	// LOOP THROUGH ALL REGIONS AND SEE IF WE HAVE A VALUE FOR THIS DELIVERY COUNTRY		 
	if(is_array($core_admin_values['regions'])){ $i=-1; while($i <= count($core_admin_values['regions'])){  $i++;
	 	
	if($core_admin_values['regions']['name'][$i] !=""  ){ 
		
			if(( is_array($core_admin_values['regions']['country'][$i]) && in_array($delivery_country, $core_admin_values['regions']['country'][$i]) ) 
			|| ( is_array($core_admin_values['regions']['state'][$i]) && in_array($delivery_country, $core_admin_values['regions']['state'][$i]) ) ) { // COUNTRY OR STATE CHECKOUT	
							 			 
				$region_name = $core_admin_values['regions']['name'][$i];
				 
				if(isset($current_free_shipping_array[$region_name]) && strlen($current_free_shipping_array[$region_name]) > 1 && $OLD_SUBTITLE > $current_free_shipping_array[$region_name] ){
 
				$c['shipping'] = 0;
	
				}
			}
				
	}}} // end if / foreach / if 
	
	// EXTRA FOR 
	if(isset($current_free_shipping_array['default']) && is_numeric($current_free_shipping_array['default']) && $current_free_shipping_array['default'] > 0){	
		if($OLD_SUBTITLE > $current_free_shipping_array['default'] ){
			$c['shipping'] = 0;	 
		}
	}
	 
}


return $c; // MUST RETURN CART DATA
}

// 2. ADD IN SOME OF THE STANDARD tax OPTIONS
function basic_tax_shipping(){ 

global $wpdb, $CORE; $core_admin_values = get_option("core_admin_values");  $current_country_tax_array = get_option('wlt_country_tax_price_array');  $current_wlt_tax_exemp_array = get_option('wlt_tax_exemp_array');
 
if(isset($_POST['admin_values']['basic_tax'])){

	// SET CUSTOM ARRAY FOR COUTNRIES SINCE THERE ARE ALOT OF THEM
	if( ( isset($_POST['basic_tax_country_price']) && is_numeric($_POST['basic_tax_country_price']) ) || ( isset($_POST['basic_tax_country_percentage']) && is_numeric($_POST['basic_tax_country_percentage']) )  ){
		$new_country_tax_array = array();	
		if(!is_array($current_country_tax_array)){ $current_country_tax_array = array(); }
		if(isset($_POST['basic_country_tax']) && !empty($_POST['basic_country_tax'])){
			foreach($_POST['basic_country_tax'] as $country){
				$new_country_tax_array[$country]['price'] 		= $_POST['basic_tax_country_price'];
				$new_country_tax_array[$country]['percent'] 	= $_POST['basic_tax_country_percentage'];
				$new_country_tax_array[$country]['excemption'] 	= $_POST['basic_tax_country_excemption'];
				
			}// end foreach	
			update_option("wlt_country_tax_price_array",array_merge($current_country_tax_array,$new_country_tax_array), true);
			$current_country_tax_array = get_option('wlt_country_tax_price_array');
			
		}// end if
	}// end if 
	
} // end if
 
$current_country_ship_array = get_option('wlt_country_ship_price_array'); $current_amount_ship_array = get_option('wlt_amount_ship_price_array'); $current_free_shipping_array = get_option('wlt_free_shipping_array');
 
if(isset($_POST['admin_values']['basic_shipping'])){

	// SET CUSTOM ARRAY FOR COUTNRIES SINCE THERE ARE ALOT OF THEM
	if(isset($_POST['basic_shipping_country_price']) && is_array($_POST['basic_shipping_country_price'])){
		
		if(!is_array($current_country_ship_array)){ $current_country_ship_array = array(); }
		
		
		if(isset($_POST['basic_country']) && !empty($_POST['basic_country'])){
			foreach($_POST['basic_country'] as $country){
				$current_country_ship_array[$_POST['basic_country_shipping_methods']][$country] = $_POST['basic_shipping_country_price'];
			}// end foreach	
			 
			update_option("wlt_country_ship_price_array",$current_country_ship_array, true);
			$current_country_ship_array = get_option('wlt_country_ship_price_array');
		}// end if
	}// end if 
	
} // end if



if(isset($_POST['free_ship_price']) && strlen($_POST['free_ship_price']) > 0){

	// SET CUSTOM ARRAY FOR COUTNRIES SINCE THERE ARE ALOT OF THEM	 
	if($_POST['basic_free_ship'] == ""){ $_POST['basic_free_ship'] = "default"; }
	
	
	
	$current_free_shipping_array[$_POST['basic_free_ship']] = $_POST['free_ship_price'];		
	 	 
	update_option("wlt_free_shipping_array",$current_free_shipping_array, true);
	$current_free_shipping_array = get_option('wlt_free_shipping_array'); 
 
	
} // end if
 

?> 


<div class="tab-pane fade <?php if(isset($_POST['tab']) && $_POST['tab'] == "basic_tax"){ echo "active in"; } ?>" id="basic_tax">

<div class="tabbable tabs-left" >
<ul id="tabExample3" class="nav nav-tabs" style="height:680px">
<li class="active"><a href="#taxtab0" data-toggle="tab">Tax Overview</a></li>
<li><a href="#taxtab1" data-toggle="tab">Flat Rate Tax</a></li>
<li><a href="#taxtab2" data-toggle="tab">Country/State Tax</a></li>
<li><a href="#taxtab3" data-toggle="tab">Per Product Tax</a></li>
<?php do_action('hook_admin_tax_tablist'); ?> 
</ul>
<div class="tab-content"  style="background:#fff;height:680px">

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

    <div class="tab-pane fade in active" id="taxtab0"> 
    
    <div class="heading1">Tax Overview</div>
    
    <h4>Taxable Items</h4>
    
    <p>Tax is applied to all products which you have specified as taxable.</p>
    <p>To set a product as taxable simply edit any product and set the value for <b>Add Tax?</b> to 'Yes'.</p>
    
    
    <div class="heading1"> Additional Price Display</div>
    <p>Here you can set a percentage amount which will be added to your website display prices. (excluding checkout)</p>
    
    <div class="row-fluid">
    
     <div class="span6">
     
        <div class="form-row control-group row-fluid">
       <label class="control-label span4" for="normal-field">Percentage (%)</label>
    <div class="controls span7">
    	<input type="text" name="admin_values[display_percentage]" class="row-fluid" value="<?php echo $core_admin_values['display_percentage']; ?>">
    </div>
        </div>
        
        
        
    </div>
      
    </div>
   
   
   
    
    </div>
    <div class="tab-pane fade in" id="taxtab1">  
    
    <div class="heading1">Flat Rate Tax</div>
    
    <p>Flat rate taxes will be added to the checkout regardless of # items or taxable value being set. </p></p>
   
    <hr  /> 
   
     <!---- FLAT RATE TEXT --->
    <div class="form-row control-group row-fluid">    
    <label class="span4">Flat Rate (fixed price)</label>
        <div class="input-prepend controls span7">
        <span class="add-on"><?php echo $core_admin_values['currency']['symbol']; ?></span>
        <input type="text" name="admin_values[basic_tax][flatrate]"  value="<?php echo $core_admin_values['basic_tax']['flatrate']; ?>" >
        
        </div> 
    </div>
    
    <hr />     
     <!---- FLAT RATE TEXT --->
    <div class="form-row control-group row-fluid">    
    <label class="span4">Flat Rate (percentage)</label>
        <div class="input-prepend controls span7">
        <span class="add-on">%</span>
        <input type="text" name="admin_values[basic_tax][flatrate_percent]"   value="<?php echo $core_admin_values['basic_tax']['flatrate_percent']; ?>" >
        
        </div> 
    </div>
 
    <hr />     
     <!---- FLAT RATE TEXT --->      
     
    </div>
    <div class="tab-pane fade in" id="taxtab2">
    
    
    <div class="heading1">Tax Per Country</div>
    
    <p>The taxable country is taken from the delivery address entered during checkout.</p>
    <hr  />
    <!-- COUNTRY TAX--->
    
            <div class="form-row control-group row-fluid ">
            <label class="control-label span4">Enable Option</label>
            <div class="controls span7">                            
            <select name="admin_values[basic_country_tax_tax]">            
            <option value="0">No</option>
            <option value="1" <?php if($core_admin_values['basic_country_tax_tax'] == '1'){ echo "selected=selected"; }  ?>>Yes</option>
            </select>
            </div> 
            </div>
            <hr />
   
               <div class="form-row control-group row-fluid">
                <label class="control-label span4">Select Region
                <a href="#regions" data-toggle="tab" class="label label-success" style="float:right;">Add New</a>  
                </label>
                <div class="controls span7">
                  
                  <select data-placeholder="Choose a region..." class="chzn-select" name="basic_country_tax[]" id="taxc1">
                    <option value=""></option>
                    
                    <?php
					if(is_array($core_admin_values['regions'])){ 
						$i=0; 
						while($i < count($core_admin_values['regions']['name']) ){
							if($core_admin_values['regions']['name'][$i] !=""){		
								$pp1 = "title='".$current_country_tax_array[$core_admin_values['regions']['name'][$i]]['price']."|".$current_country_tax_array[$core_admin_values['regions']['name'][$i]]['percent']."|'";				
								echo "<option value='".$core_admin_values['regions']['name'][$i]."' ".$pp1." id='".$i."'>".$core_admin_values['regions']['name'][$i]."</option>";	
								
							} // end if
							$i++;
						} // end foreach
					}// end if				 
					?>                    
                  </select>
                  
                  </div></div>
      
           <script>
			jQuery(document).ready(function(){
				jQuery( "#taxc1" ).change(function() {				 
					var sdt = jQuery("option:selected", this).attr("title");						 	 
					if(sdt != ""){	
					var exploded = sdt.split('|');
					 jQuery('#taxc_p').val(exploded[0]);
					 jQuery('#taxc_pp').val(exploded[1]);
					}
				});		
			});
			</script> 
<!---- FIELD --->
<div class="form-row control-group row-fluid">
<label class="span4">Set Price Per Product</label>
    <div class="input-prepend controls span7">
    <span class="add-on"><?php echo $core_admin_values['currency']['symbol']; ?></span>
    <input type="text" name="basic_tax_country_price" id="taxc_p" value="" >    
    </div> 
</div>
 
<!---- FIELD ---> 
<div class="form-row control-group row-fluid">
<label class="span4">Set Percentage Per Product</label>
    <div class="input-prepend controls span7">
    <span class="add-on">%</span>
    <input type="text" name="basic_tax_country_percentage" id="taxc_pp" value="" >
    
    </div> 
</div>
 

<p><span class="label">Note</span> Tax will be set per item and will only apply to products which are set as taxable.</p>
<hr />
<div class="well">
<b>Tax Exemption (optional extra)</b>
<p><small>Products with the custom field below will be except from percentage Tax calculations above.</small></p>
<div class="form-row control-group row-fluid">
<label class="span4">Custom Field</label>
    <div class=" controls span7">
    <input type="text" name="basic_tax_country_excemption" id="layout_body4" value="" >
     
    </div> 
</div>
</div>
<!---- FIELD --->     
    
    <!-- END COUNTRY TAX --->
</div>    
    <div class="tab-pane fade in" id="taxtab3">
    
    <div class="heading1">Tax Per Product</div>
    <p>Enable this if you wish the shopping cart to calculate tax for each item based on the amount you set per time.</p>
    <hr />
    
            <div class="form-row control-group row-fluid ">
            <label class="control-label span4">Enable Option</label>
            <div class="controls span7">                            
            <select name="admin_values[per_product_tax][enable]">            
            <option value="0">No</option>
            <option value="1" <?php if($core_admin_values['per_product_tax']['enable'] == '1'){ echo "selected=selected"; }  ?>>Yes</option>
            </select>
            </div> 
            </div>
            <hr />           
   
      <input type="hidden" name="admin_values[per_product_tax][key]" value="tax_amount" />
      
    </div>    
</div>
</div>  

<div class="form-actions row-fluid"><div class="span7 offset5"><button type="submit" class="btn btn-primary" onclick="document.getElementById('ShowTab').value='basic_tax'">Save Changes</button></div></div>

</div><!-- END TAX OPTIONS -->



<div class="tab-pane fade <?php if(isset($_POST['tab']) && $_POST['tab'] == "basic_shipping"){ echo "active in"; } ?>" id="basic_shipping">

<div class="tabbable tabs-left" >
<ul id="tabExample4" class="nav nav-tabs" style="height:680px">
<li class="active"><a href="#shiptab0" data-toggle="tab">Shipping Overview</a></li>
<li><a href="#shiptab1" data-toggle="tab">Flat Rate Shipping</a></li>
<li><a href="#shiptab2" data-toggle="tab">Country Rate Shipping</a></li>
<li><a href="#shiptab3" data-toggle="tab">Free Shipping</a></li> 
<li><a href="#shiptab4" data-toggle="tab">Weight Based Shipping</a></li>
<?php do_action('hook_admin_shipping_tablist'); ?> 
</ul>
<div class="tab-content"  style="background:#fff;height:680px">

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

    <div class="tab-pane fade in active" id="shiptab0">
    
    <div class="heading1">Shipping Overview</div>
    
    <h4>Staying Safe Online</h4>
    <p>To help you and your business combat transaction and credit card fraud, we strongly recommend you only ship to the payers verified billing address and contact customers before shipping items to verify their details.</p>   
     
    <h4>Shipping Charges</h4>
    
    <p>Shipping charges are applied to all products which you have specified as shippable.</p>
    
    <p>To set a product as shippable, simply edit the product and set <b>Add Shipping Charges?</b> to 'yes'</p>
 
    
    
    </div>
    <div class="tab-pane fade in" id="shiptab1">
	
    <div class="heading1">Flat Rate Shipping</div>    
	<p>The value here will be added to the checkout regardless of country or cart items.</p>
    <hr />
    
    <!---- FIELD --->
    <div class="form-row control-group row-fluid">
    	<label class="span4">Shipping Price (fixed price)</label>    
        <div class="input-prepend controls span7">
        <span class="add-on"><?php echo $core_admin_values['currency']['symbol']; ?></span>
        <input type="text" name="admin_values[basic_shipping][flatrate]"  value="<?php echo $core_admin_values['basic_shipping']['flatrate']; ?>" >        
        </div> 
    </div>
    <hr />
    <!---- FIELD --->
     <!---- FIELD --->
    <div class="form-row control-group row-fluid">
    	<label class="span4">Shipping Price (percentage)</label>
        <div class="input-prepend controls span7">
        <span class="add-on">%</span>
        <input type="text" name="admin_values[basic_shipping][flatrate_percent]" value="<?php echo $core_admin_values['basic_shipping']['flatrate_percent']; ?>" >        
        </div> 
    </div>
    <hr />
    <!---- FIELD ---> 
    
     
    </div>
    <div class="tab-pane fade in" id="shiptab2">
    
    <div class="heading1">Country Rate Shipping</div>
    
    <p>Cart prices are <b>calculated per item</b> and only apply to products which are set as <b>require shipping</b>.</p>
    <p>The customers country is taken from the delivery address they set at checkout.</p>
	<hr />
       
            <div class="form-row control-group row-fluid ">
            <label class="control-label span4">Enable Option</label>
            <div class="controls span7">                            
            <select name="admin_values[basic_country_shipping]">            
            <option value="0">No</option>
            <option value="1" <?php if($core_admin_values['basic_country_shipping'] == '1'){ echo "selected=selected"; }  ?>>Yes</option>
            </select>
            </div> 
            </div>
            <hr /> 
            
            <div class="form-row control-group row-fluid ">
            <label class="control-label span4">Select Method <a href="javascript:void(0);" onclick="addnewmethod();" class="label label-success" style="float:right;">Add New</a>  <br /><small>e.g. Ground Shipping</small> </label>
            <div class="controls span7"> 
                                      
            <select name="basic_country_shipping_methods" id="shipping_methods">            
            <option value="default">Default - Non-Displayed</option>
            <?php 
			if(isset($core_admin_values['cart_method_list']) && is_array($core_admin_values['cart_method_list'])){
				foreach($core_admin_values['cart_method_list'] as $method){ if(strlen($method) > 1){
					echo "<option>".$method."</option>";
				} }		
			}
			?>           
            </select>
            <script>
			jQuery(document).ready(function(){
				jQuery( "#shipping_methods" ).change(function() {				
					 jQuery('#shipc1').val([]).trigger('liszt:updated');
					 jQuery('#ship_price_type0').val('');
					 jQuery('#ship_price_type1').val('');
					 jQuery('#ship_price_type2').val('');
					 jQuery('#ship_price_type3').val('');
				});		
			});
			</script>  
           <style>
		   #hiddenmethods li { display:block; }
		   </style>
          
            <ul id="hiddenmethods">
            
            <?php 
			$mt = 0;
			if(isset($core_admin_values['cart_method_list']) && is_array($core_admin_values['cart_method_list'])){
				foreach($core_admin_values['cart_method_list'] as $method){ if(strlen($method) > 1){
					echo "<li id='wlt_method_id_".$mt."'>".$method." (<a href=\"javascript:void(0);\" onclick=\"jQuery('#wlt_method_id_".$mt."').html('');\">remove</a>)
					<input type='hidden' name='admin_values[cart_method_list][]' value='".$method."'>
					</li>";
					$mt++;
				} }		
			}
			// ADD ON EXTRA ONE SO THE SYSTEM WILL SAVE 
			echo "<input type='hidden' name='admin_values[cart_method_list][]' value='0'>";
			?>            
            </ul>
             
            </div> 
            </div>
            <hr />
            
            <script>			
				function addnewmethod(){

					var mt=prompt("Please enter a method title:","");
					if (mt!= null){  					
					jQuery("#shipping_methods").append(jQuery("<option></option>").attr("value",mt).text(mt));
					jQuery("#hiddenmethods").append(jQuery("<li></li>").html("<input type='hidden' name='admin_values[cart_method_list][]' value='"+mt+"'>"+mt));	
					
					}				
					 
				}
			 
			</script>       
       
<div class="form-row control-group row-fluid">
                <label class="control-label span4">Select Region
                <a href="#regions" data-toggle="tab" class="label label-success" style="float:right;">Add New</a>  
                </label>
                <div class="controls span7">
                  
                  <select data-placeholder="Choose a region..." class="chzn-select" name="basic_country[]" id="shipc1">
                    <option value=""></option>
                    
                    <?php
					if(is_array($core_admin_values['regions'])){ 
						$i=0; 
						while($i < count($core_admin_values['regions']['name']) ){
							if($core_admin_values['regions']['name'][$i] !=""){						
								echo "<option value='".$core_admin_values['regions']['name'][$i]."'  id='".$i."'>".$core_admin_values['regions']['name'][$i]."</option>";	
								
							} // end if
							$i++;
						} // end foreach
					}// end if				 
					?>                    
                  </select>
<?php	
 
	if(!isset($core_admin_values['cart_method_list'])){ $methods = array('default'); }else{ $methods = array_merge(array('default'), $core_admin_values['cart_method_list']); } 
	foreach($methods as $method){ if(strlen($method) > 1){
		// NOW LOOP ALL REGIONS FOR THIS METHOD
		 
		if(isset($current_country_ship_array[$method])){			 
			foreach($current_country_ship_array[$method] as $key=>$data){ 															
				echo "<input type='hidden' id='hh_".str_replace("%","",str_replace("(","",str_replace(")","",str_replace(" ","",strtolower($method."-".$key)))))."' value='".$data[0]."|".$data[1]."|".$data[2]."|".$data[3]."' />";	 				 
				
			} // end foreach
		}// end if	
	} }
?>	                 
<script type="application/javascript">
jQuery(document).ready(function(){		 
	jQuery( "#shipc1" ).change(function() {	
 
 		var mid = jQuery('#shipping_methods').val().toLowerCase().replace(/\s+/g, "").replace("(", "").replace(")", "").replace("%", "");		 
		var cid = jQuery('#shipc1').val().toLowerCase().replace(/\s+/g, "").replace("(", "").replace(")", "").replace("%", "");
		
		var sdt = jQuery('#hh_' + mid + '-' + cid).val();		 
		if(sdt != ""){	
		var exploded = sdt.split('|');
		 jQuery('#ship_price_type0').val(exploded[0]);
		 jQuery('#ship_price_type1').val(exploded[1]);
		 jQuery('#ship_price_type2').val(exploded[2]);
		 jQuery('#ship_price_type3').val(exploded[3]);
		}
	}); 
});
</script>
                  </div></div>
      
      
<!---- FIELD --->
<hr />
<?php $types = array("0"=>"Light", "1"=>"Medium", "2" => "Heavy", "3" => "Very Heavy" );
foreach($types as $key=>$tt){
?>
<div class="form-row control-group row-fluid">
<label class="span4">Price (<?php echo $tt; ?> Items)</label>
    <div class="input-prepend controls span7">
    <span class="add-on"><?php echo $core_admin_values['currency']['symbol']; ?></span>
    <input type="text" name="basic_shipping_country_price[<?php echo $key; ?>]" id="ship_price_type<?php echo $key; ?>" value="" >    
    </div> 
</div>
<?php } ?>

 
<!---- FIELD --->       
       
    </div> 
    
    
    <div class="tab-pane fade in" id="shiptab3">
  
    <div class="heading1">Free Shipping</div>
    
    <p>Here you can setup free shipping for orders over XXX to different regions.</p>

	<hr />
    
             <div class="form-row control-group row-fluid ">
            <label class="control-label span4">Enable Option</label>
            <div class="controls span7">                            
            <select name="admin_values[basic_free_shipping]">            
            <option value="0">No</option>
            <option value="1" <?php if($core_admin_values['basic_free_shipping'] == '1'){ echo "selected=selected"; }  ?>>Yes</option>
            </select>
            </div> 
            </div>
            <hr />
    
    
   <div class="form-row control-group row-fluid">
                <label class="control-label span4">Select Region
                <a href="#regions" data-toggle="tab" class="label label-success" style="float:right;">Add New</a>  
                </label>
                <div class="controls span7">
                
                  <select data-placeholder="Choose a region..." class="chzn-select" name="basic_free_ship" id="freeship">
                    <option value="" title='<?php echo $current_free_shipping_array['default']; ?>'>All Regions</option>
                    
                    <?php
					if(is_array($core_admin_values['regions'])){ 
						$i=0; 
						while($i < count($core_admin_values['regions']['name']) ){
							if($core_admin_values['regions']['name'][$i] !=""){		
								
								$pp1 = "title='".$current_free_shipping_array[$core_admin_values['regions']['name'][$i]]."|'";				
								echo "<option value='".$core_admin_values['regions']['name'][$i]."' ".$pp1." id='".$i."'>".$core_admin_values['regions']['name'][$i]."</option>";	
								
							} // end if
							$i++;
						} // end foreach
					}// end if				 
					?>                    
                  </select>
                  
                  </div></div>
      
           <script>
			jQuery(document).ready(function(){
				jQuery( "#freeship" ).change(function() {				 
					var sdt = jQuery("option:selected", this).attr("title");						 	 
					if(sdt != ""){	
					var exploded = sdt.split('|');
					 jQuery('#free_ship_price').val(exploded[0]);
					 
					}
				});		
			});
			</script> 
             
<hr />  
<div class="form-row control-group row-fluid">
<label class="span4">Orders Over</label>
    <div class="input-prepend controls span7">
    <span class="add-on">$</span>
    <input type="text" name="free_ship_price" id="free_ship_price" value="<?php if(isset($current_free_shipping_array['default']) && $current_free_shipping_array['default'] > 0){ echo $current_free_shipping_array['default']; } ?>">    
    </div> 
</div>  
    
    
    
    
    </div>   
	
	  
      
      
      
<div class="tab-pane fade in" id="shiptab4">

<a href="javascript:void(0);" onClick="jQuery('#wlt_weightbox').clone().prependTo('#wlt_weightbased_shpping');" class="btn btn-success" style="float:right;">Add New</a>	   
<div class="clearfix"></div>
<hr />

<ul id="wlt_weightbased_shpping">

 
<?php 

$backupRegions = $core_admin_values['weightship'];
if(is_array($core_admin_values['weightship']) && !empty($core_admin_values['weightship'])){ $wi=0;  
foreach($core_admin_values['weightship']['region'] as $weightopK){ 
 

    	$regcode = ""; $regse = "";
		if(is_array($core_admin_values['regions'])){ 
					$i=0; 
					while($i < count($core_admin_values['regions']['name']) ){
						if($core_admin_values['regions']['name'][$i] !=""){
							if($core_admin_values['weightship']['region'][$wi] == $core_admin_values['regions']['name'][$i]){ $regse = $core_admin_values['regions']['name'][$i]; $ss = "selected=selected"; }else{ $ss = ""; }
							
							$regcode .= "<option value='".$core_admin_values['regions']['name'][$i]."' ".$ss." id='".$i."'>".$core_admin_values['regions']['name'][$i]."</option>";	
								
					} // end if
					$i++;
				} // end foreach
		}// end if				 


if($core_admin_values['weightship']['pricea'][$wi] == ""){ $wi++; continue; }	 
?>

    <li class="postbox" style="padding:5px;" id="ewbs<?php echo $wi; ?>"> 
    
    
    <div class="inside1">           
    
    
    <h3 class="hndle" style="margin-bottom:0px;" id="ewbsinner<?php echo $wi; ?>_handle">
    
	<?php echo $regse; ?> :: (<?php echo $core_admin_values['weightship']['pricea'][$wi]; ?> &amp; <?php echo $core_admin_values['weightship']['priceb'][$wi]; ?> = <?php echo hook_price($core_admin_values['weightship']['pricec'][$wi]); ?>)
    
    
    <a href="javascript:void(0);" onClick="jQuery('#ewbsinner<?php echo $wi; ?>_handle').hide();jQuery('#ewbsinner<?php echo $wi; ?>').show();" class="label label-important" style="float:right;">Show</a>
    </h3>
     
     
    <div id="ewbsinner<?php echo $wi; ?>"  style="display:none;padding:20px;">
            
    <a href="javascript:void(0);" onClick="jQuery('#ewbsinner<?php echo $wi; ?>_handle').show();jQuery('#ewbsinner<?php echo $wi; ?>').hide();" class="label label-important" style="float:right;">Hide</a>
   <div class="clearfix"></div> 
  <div class="row-fluid">     
    <div class="span6">Select Region</div>
    <div class="span6">
    <select name="admin_values[weightship][region][]" id="wship1">
     <option value=""></option>
                <?php echo $regcode; ?>
    </select>
    </div>
    </div>
    <hr />
    <div class="row-fluid">
    <div class="span4">
     Between
    <div class="controls">         
     <div class="input-prepend">
      <span class="add-on">Weight</span>
      <input type="text" name="admin_values[weightship][pricea][]" value="<?php echo $core_admin_values['weightship']['pricea'][$wi]; ?>" style="width:150px;text-align:right" id="ewbs<?php echo $wi; ?>_d1" /> 
    </div>        
    </div>    
    </div>
    <div class="span4">And
    
    <div class="controls">         
     <div class="input-prepend">
      <span class="add-on">Weight</span>
      <input type="text" name="admin_values[weightship][priceb][]" value="<?php echo $core_admin_values['weightship']['priceb'][$wi]; ?>" style="width:150px;text-align:right" />
    </div>        
    </div>
    
    </div>
    <div class="span4">Price Per Item
    
    <div class="controls">         
     <div class="input-prepend">
      <span class="add-on">$</span>
      <input type="text" name="admin_values[weightship][pricec][]" value="<?php echo $core_admin_values['weightship']['pricec'][$wi]; ?>" style="width:150px;text-align:right" />
    </div>        
    </div>
 
    </div>  
    </div>
    <hr />
    
    <a href="javascript:void(0);" onClick="jQuery('#ewbs<?php echo $wi; ?>_d1').val('');jQuery('#ewbs<?php echo $wi; ?>').hide();" class="label label-important" style="float:right;">Remove Field</a>
   
    <button type="submit" class="btn btn-default" onclick="document.getElementById('ShowTab').value='basic_shipping';document.getElementById('ShowSubTab').value='shiptab4'">Save</button>
    </div>
    </li> 

<?php $wi++; } } ?>

</ul>

<!-- DEFAULT BOX CODE --->
<div style="display:none"><div id="wlt_weightbox">
    <li class="postbox" STYLE="border:1px solid red;padding:10px;">
 
    <div class="inside"> 
          
          
    <div class="row-fluid">
    <div class="span6">Select Region</div>
    <div class="span6">
    <select name="admin_values[weightship][region][]" id="wship1">
     <option value=""></option>
     <?php
		if(is_array($core_admin_values['regions'])){ 
					$i=0; 
					while($i < count($core_admin_values['regions']['name']) ){
						if($core_admin_values['regions']['name'][$i] !=""){
							echo "<option value='".$core_admin_values['regions']['name'][$i]."' ".$pp1." id='".$i."'>".$core_admin_values['regions']['name'][$i]."</option>";	
								
					} // end if
					$i++;
				} // end foreach
		}// end if				 
	?>                    
    </select>
    </div>
    </div>
    <hr />
    <div class="row-fluid">
    <div class="span4">
     Between
    <div class="controls">         
     <div class="input-prepend">
      <span class="add-on">Weight</span>
      <input type="text" name="admin_values[weightship][pricea][]" value="" style="width:150px;text-align:right" /> 
    </div>        
    </div>    
    </div>
    <div class="span4">And
    
    <div class="controls">         
     <div class="input-prepend">
      <span class="add-on">Weight</span>
      <input type="text" name="admin_values[weightship][priceb][]" value="" style="width:150px;text-align:right" />KG
    </div>        
    </div>
    
    </div>
    <div class="span4">Price
    
    <div class="controls">         
     <div class="input-prepend">
      <span class="add-on">$</span>
      <input type="text" name="admin_values[weightship][pricec][]" value="" style="width:150px;text-align:right" />KG
    </div>        
    </div>
 
    </div>  
    </div>
    <hr />
    <button type="submit" class="btn" onclick="document.getElementById('ShowTab').value='basic_shipping';document.getElementById('ShowSubTab').value='shiptab4'">Save</button>
    </div>
    </li> 
</div>
</div> 
<!-- DEFAULT BOX CODE --->

  
  </div>
  
  
  
      
      
</div>
</div>  

<div class="form-actions row-fluid"><div class="span7 offset5"><button type="submit" class="btn btn-primary" onclick="document.getElementById('ShowTab').value='basic_shipping'">Save Changes</button></div>
</div>






</div><!-- END SHIPPING OPTIONS -->


<div class="tab-pane fade <?php if(!isset($_POST['tab']) || isset($_POST['tab']) && $_POST['tab'] == "regions"){ echo "active in"; } ?>" id="regions">


<a href="#quickAdd" role="button" class="btn" data-toggle="modal" class="btn btn-success" style="float:right;margin-left:10px;">Quick Add</a>	   
<a href="javascript:void(0);" onClick="jQuery('#wlt__regions').clone().insertAfter('#wlt__regionss');" class="btn btn-success" style="float:right;">Add New</a>	   



 
<!-- Modal -->
<div id="quickAdd" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="quickAddLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
    <h3 id="myModalLabel">Quick Add</h3>
  </div>
  <div class="modal-body">

 
        <h4 class="media-heading">USA Tax States</h4>
        <p>Select this option if you wish you add the predefined tax regions to your website.</p>
        <a href="admin.php?page=9&add_pre_usa=1" class="btn btn-info">Select Option</a> - remember to save changes.
        <hr />
        
        <h4 class="media-heading">Canadian Tax States</h4>
        <p>Select this option if you wish you add the Canadian tax regions.</p>
        <a href="admin.php?page=9&add_pre_usa=3" class="btn btn-info">Select Option</a> - remember to save changes.
        <hr />    
        
        <h4 class="media-heading">European Union Countries</h4>
        <p>Select this option if you wish you add the European Union countries.</p>
        <a href="admin.php?page=9&add_pre_usa=2" class="btn btn-info">Select Option</a> - remember to save changes.
        <hr />         
               
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>

  </div>
</div>


<h2>Regions</h2>

<p>Regions let you setup country/state combinations which can be used for custom tax and shipping prices.</p>

<p><b class="label label-info">Note:</b> If you are applying the same tax/ship price for the entire country, you <u>do not</u> need to add all of the states/provinces as well.</p>

<?php

if(isset($_GET['add_pre_usa']) && !isset($_POST['tab'])){

	$df = 0;	
	while($i < count($core_admin_values['regions']['name']) ){ if($core_admin_values['regions']['name'][$i] !=""){ 
	$df++;
	} }
	
	if($_GET['add_pre_usa'] == 1){
	
		$core_admin_values['regions']['name'][$df] = 'USA (0% Tax States Only)';
		$core_admin_values['regions']['country'][$df] = array('');
		$core_admin_values['regions']['state'][$df] = array('Alaska','Delaware','Montana','New Hampshire','Oregon');		
		$df++;
		$core_admin_values['regions']['name'][$df] = 'USA (2.9% Tax States Only)';  
		$core_admin_values['regions']['country'][$df] = array('');
		$core_admin_values['regions']['state'][$df] = array('Colorado');
		$df++;
		$core_admin_values['regions']['name'][$df] = 'USA (4% Tax States Only)'; 
		$core_admin_values['regions']['country'][$df] = array('');
		$core_admin_values['regions']['state'][$df] = array('Alabama','Georgia','Guam','Hawaii','Louisiana','Missouri','New York','Oklahoma','South Dakota','Wyoming');
		$df++;
		$core_admin_values['regions']['name'][$df] = 'USA (5% Tax States Only)';  
		$core_admin_values['regions']['country'][$df] = array('');
		$core_admin_values['regions']['state'][$df] = array('Maine','Nebraska','New Mexico','North Carolina','North Dakota','Puerto Rico','Utah','Wisconsin');
		$df++;
		$core_admin_values['regions']['name'][$df] = 'USA (6% Tax States Only)'; 
		$core_admin_values['regions']['country'][$df] = array('');
		$core_admin_values['regions']['state'][$df] = array('Arkansas','District of Columbia','Florida','Idaho','Iowa','Kansas','Kentucky','Maryland','Massachusetts','Michigan','Ohio','Pennsylvania','South Carolina','Vermont','Virginia','West Virginia');
		$df++;
		$core_admin_values['regions']['name'][$df] = 'USA (6.6% Tax States Only)'; 
		$core_admin_values['regions']['country'][$df] = array('');
		$core_admin_values['regions']['state'][$df] = array('Arizona','Connecticut','Illinois','Minnesota','Nevada','Texas','Washington');
		$df++;
		$core_admin_values['regions']['name'][$df] = 'USA (7.5% Tax States Only)';
		$core_admin_values['regions']['country'][$df] = array('');
		$core_admin_values['regions']['state'][$df] = array('California','Indiana','Mississippi','New Jersey','Rhode Island','Tennessee');
	 
	}elseif($_GET['add_pre_usa'] == 2){
	
		$core_admin_values['regions']['name'][$df] = 'EU - European Union Countries';
		$core_admin_values['regions']['country'][$df] = array('AT','BE','BG','HR','CY','CZ','DE','EE','FI','FR','DE','GR','HU','IS','IT','LV','LT','LU','MT','NL','PL','PT','RO','SK','SI','SP','SE','UK');
		$core_admin_values['regions']['state'][$df] = array('');
		
	}elseif($_GET['add_pre_usa'] == 3){
	
		$core_admin_values['regions']['name'][$df] = 'CA (5% Tax States Only)';
		$core_admin_values['regions']['country'][$df] = array('');
		$core_admin_values['regions']['state'][$df] = array('Alberta');
		$df++;
		$core_admin_values['regions']['name'][$df] = 'CA (10% Tax States Only)';
		$core_admin_values['regions']['country'][$df] = array('');
		$core_admin_values['regions']['state'][$df] = array('Saskatchewan');
		$df++;	
		$core_admin_values['regions']['name'][$df] = 'CA (12% Tax States Only)';
		$core_admin_values['regions']['country'][$df] = array('');
		$core_admin_values['regions']['state'][$df] = array('British Columbia');
		$df++;		
		$core_admin_values['regions']['name'][$df] = 'CA (13% Tax States Only)';
		$core_admin_values['regions']['country'][$df] = array('');
		$core_admin_values['regions']['state'][$df] = array('Manitoba','Ontario','New Brunswick','Newfoundland');
		$df++;	
		$core_admin_values['regions']['name'][$df] = 'CA (14% Tax States Only)';
		$core_admin_values['regions']['country'][$df] = array('');
		$core_admin_values['regions']['state'][$df] = array('Quebec','Prince Edward Island');
		$df++;			
		$core_admin_values['regions']['name'][$df] = 'CA (15% Tax States Only)';
		$core_admin_values['regions']['country'][$df] = array('');
		$core_admin_values['regions']['state'][$df] = array('Nova Scotia');			
	} 
}

?>
<style>
.closed { display:none; }
</style>
<div class="well" style="border:0px;">
<ul id="wlt__regionss">
<?php 
  
// COUNTRY LIST
$country_string1 = "";
foreach($GLOBALS['core_country_list'] as $key=>$value){
	$country_string1 .= "<option value='".$key."'>".$value."</option>";
} // end if 

// STATE LIST
$state_string1 = "";
foreach($GLOBALS['core_country_list'] as $key=>$value){
	$state_string1 .= "<optgroup label='".$value."' class='".$key."_state'>";	
						
	// NOW LETS CHECK FOR STATES
	if(isset($GLOBALS['core_state_list'][$key])){
		$bits = explode("|",$GLOBALS['core_state_list'][$key]);
		foreach($bits as $st){
			if(isset($selected_state) && $selected_state == $value){ $sel ="selected=selected"; }else{ $sel =""; }
			$state_string1 .= '<option value="'.$st.'">'.$st.'</option>';
		} // end if
							
	}// end if
						
	$state_string1 .= "</optgroup>";										
} // end if
  
if(is_array($core_admin_values['regions'])){ $i=0; 

while($i < count($core_admin_values['regions']['name']) ){ if($core_admin_values['regions']['name'][$i] !=""){  ?>
    <li class="postbox" id="method_<?php echo $i; ?>">
    
    <div class="label label-info" id="region_label_<?php echo $i; ?>" style="float:right;margin-top:10px;margin-right:10px;cursor:pointer" 
    onclick="jQuery('#region_label_<?php echo $i; ?>').hide();jQuery('#region_labels_<?php echo $i; ?>').show();jQuery('#region_inside_<?php echo $i; ?>').removeClass( 'closed' );">Show Details</div>

    <div class="label label-warning" id="region_labels_<?php echo $i; ?>" style="float:right;margin-top:10px;margin-right:10px;cursor:pointer;display:none;" 
    onclick="jQuery('#region_labels_<?php echo $i; ?>').hide();jQuery('#region_label_<?php echo $i; ?>').show(); jQuery('#region_inside_<?php echo $i; ?>').addClass( 'closed' );">Hide Details</div>
     
    <h3 class="hndle"> &nbsp;&nbsp; <a href="javascript:void(0);" onClick="jQuery('#method_<?php echo $i; ?>_d1').val('');jQuery('#method_<?php echo $i; ?>').hide();" class="label label-important">Remove Field</a> &nbsp;Region: <?php echo $core_admin_values['regions']['name'][$i]; ?>
    </h3>
    <div class="inside closed" id="region_inside_<?php echo $i; ?>">       
    <p>Display Text <small>(e.g European Region)</small></p>
    <input type="text" name="admin_values[regions][name][]" value="<?php echo $core_admin_values['regions']['name'][$i]; ?>"  style="width:100%; font-size:11px;" id="method_<?php echo $i; ?>_d1"  /> 
     
 
<select data-placeholder="Select Countries..." class="chzn-select" name="admin_values[regions][country][<?php echo $i; ?>][]" id="region_country_<?php echo $i; ?>" multiple="multiple">
<option value="">&nbsp;</option>
<?php
$country_string = $country_string1;

// ADD ON SELECTED ITEMS
if(isset($core_admin_values['regions']['country'][$i]) && is_array($core_admin_values['regions']['country'][$i]) ){
	foreach($core_admin_values['regions']['country'][$i] as $selected_countries){
		if(isset($selected_countries) && strlen($selected_countries) > 1){	 
			$country_string = str_replace($selected_countries."'",$selected_countries."' selected=selected",$country_string);	
		}
	}
}

echo $country_string;
?>
</select>  



<script>
jQuery(document).ready(function(){
      jQuery("#region_country_<?php echo $i; ?>").change(function(){ 
        
		if(confirm("Would you like to add the states/provinces for this country?\n\n\n If you are applying the same tax/ship price for the entire country, you do not need to add states/provinces.")){
		
			alert('Please wait a moment while we update the state list for you. (the window may freeze for a moments)');
		    var cla = jQuery("#region_country_<?php echo $i; ?>").val();	
   			jQuery.each( cla, function( key, value ) {
				jQuery("."+value+"_state").children().attr('selected','selected').trigger('liszt:updated');
			});	
		}else{
			//Cancel button pressed...
		} 
		
		 		
      });	  
});
</script>                  

<select data-placeholder="Select States..." class="chzn-select" name="admin_values[regions][state][<?php echo $i; ?>][]" id="region_state_<?php echo $i; ?>" multiple="multiple">
<option value=""></option>
<?php
$state_string = $state_string1;
// ADD ON SELECTED ITEMS
if(isset($core_admin_values['regions']['state'][$i]) && is_array($core_admin_values['regions']['state'][$i]) ){
	foreach($core_admin_values['regions']['state'][$i] as $selected_states){
		if(isset($selected_states) && strlen($selected_states) > 1){	 
			$state_string = str_replace($selected_states.'"',$selected_states.'" selected=selected',$state_string);	
		}
	}
}
echo $state_string;
?>
</select>  
                      
    <hr /> 
    <button type="submit" class="btn btn-success" onclick="document.getElementById('ShowTab').value='regions'">Save Changes</button>   
    <div class="clear"></div>
    </div>
    </li> 
<?php } $i++;  } } ?>
</ul>
</div>

<!-- DEFAULT BOX CODE --->
<div style="display:none"><div id="wlt__regions">
    <div class="postbox" STYLE="border:1px solid red;">
    <div title="Click to toggle" class="handlediv"></div>
    <h3 class="hndle">&nbsp;&nbsp;&nbsp;Region Settings</h3>
    <div class="inside">       
    <p>Display Text <small>(e.g European Region)</small></p>
    <input type="text" name="admin_values[regions][name][]" value=""  style="width:100%; font-size:11px;"  />  
    
    <button type="submit" class="btn" onclick="document.getElementById('ShowTab').value='regions'">Save</button>
    </div>
    </div> 
</div>
</div> 
<!-- DEFAULT BOX CODE --->


<div class="form-actions row-fluid"><div class="span7 offset5"><button type="submit" class="btn btn-primary" onclick="document.getElementById('ShowTab').value='regions'">Save Changes</button></div></div>

 
</div>


<style>
.postbox h3, #namediv h3, #submitdiv h3 { border:0px; }
</style>

<?php }


?>