<?php
//Option addon
$all_options = get_option( 'exwoofood_options' );
//$disable_exoptions = exwoofood_get_option('exwoofood_disable_exoptions','exwoofood_options');
if(!isset($all_options['exwoofood_disable_exoptions']) || $all_options['exwoofood_disable_exoptions']!='yes' ){
	include plugin_dir_path(__FILE__).'product-options-addon/product-options-addon.php';
}
//shortcode
include plugin_dir_path(__FILE__).'shortcodes/woo-food-list.php';
include plugin_dir_path(__FILE__).'shortcodes/woo-food-grid.php';
include plugin_dir_path(__FILE__).'shortcodes/woo-food-table.php';
include plugin_dir_path(__FILE__).'shortcodes/woo-food-carousel.php';
include plugin_dir_path(__FILE__).'shortcodes/woo-food-opcls-time.php';
include plugin_dir_path(__FILE__).'shortcodes/woo-food-opcls-table.php';
include plugin_dir_path(__FILE__).'shortcodes/woo-food-menu-group.php';
include plugin_dir_path(__FILE__).'shortcodes/woo-food-orderbt.php';
include plugin_dir_path(__FILE__).'shortcodes/woo-food-mini-cart.php';
//widget
include plugin_dir_path(__FILE__).'widgets/woo-food.php';
// woo hook
include plugin_dir_path(__FILE__).'woo-hook.php';
// Menu by date
if(isset($all_options['exwoofood_foodby_date']) && $all_options['exwoofood_foodby_date']=='yes'){
	include plugin_dir_path(__FILE__).'food-by-date.php';
}
if(isset($all_options['exwoofood_foodby_odmt']) && $all_options['exwoofood_foodby_odmt']=='yes'){
	include plugin_dir_path(__FILE__).'food-by-odmt.php';
}
if(isset($all_options['exwoofood_enable_loc']) && $all_options['exwoofood_enable_loc']=='yes'){
	include plugin_dir_path(__FILE__).'food-by-loc.php';
}
if(!isset($all_options['exwoofood_disable_minax']) || (isset($all_options['exwoofood_disable_minax']) && $all_options['exwoofood_disable_minax']!='yes') ){
	include plugin_dir_path(__FILE__).'minmax-quantity.php';
}
// Radius shipping
include plugin_dir_path(__FILE__).'shipping.php';
// Tipping 
include plugin_dir_path(__FILE__).'tip.php';
include plugin_dir_path(__FILE__).'coupon-restrict.php';
// Order on whatsapp 
include plugin_dir_path(__FILE__).'order-whatsapp.php';
// Checkout block integration 
if(isset($all_options['exwoofood_enable_sc_block']) && $all_options['exwoofood_enable_sc_block']=='yes'){
	include plugin_dir_path(__FILE__).'woo-ckblock-integration.php';
}
// New place api 
$shpping_options = get_option( 'exwoofood_shpping_options' );
if(isset($shpping_options['exwoofood_new_apis']) && $shpping_options['exwoofood_new_apis']=='yes'){
	include plugin_dir_path(__FILE__).'/map-api/functions.php';
}
if(!function_exists('exwoofood_startsWith')){
	function exwoofood_startsWith($haystack, $needle)
	{
		return !strncmp($haystack, $needle, strlen($needle));
	}
} 
if(!function_exists('exwoofood_get_google_fonts_url')){
	function exwoofood_get_google_fonts_url ($font_names) {
	
		$font_url = '';
	
		$font_url = add_query_arg( 'family', urlencode(implode('|', $font_names)) , "//fonts.googleapis.com/css" );
		return $font_url;
	} 
}
if(!function_exists('exwoofood_get_google_font_name')){
	function exwoofood_get_google_font_name($family_name){
		$name = $family_name;
		if(exwoofood_startsWith($family_name, 'http')){
			// $family_name is a full link, so first, we need to cut off the link
			$idx = strpos($name,'=');
			if($idx > -1){
				$name = substr($name, $idx);
			}
		}
		$idx = strpos($name,':');
		if($idx > -1){
			$name = substr($name, 0, $idx);
			$name = str_replace('+',' ', $name);
		}
		return $name;
	}
}
if(!function_exists('exwoofood_template_plugin')){
	function exwoofood_template_plugin($pageName,$shortcode=false){
		$all_templates = apply_filters('exwf_templates_args',array('cart-mini','grid-1','grid-2','grid-3','grid-4','grid-5','list-1','list-2','list-3','list-4','list-5','live-total','mobile-nav-bar','modal','order-method','review','product_attributes','table-1','table-2'));
		if(!in_array($pageName,$all_templates)){
			echo ' INVALID TEMPLATE ';
			return;
		}
		if(isset($shortcode) && $shortcode== true){
			if (locate_template('woocommerce-food/content-shortcodes/content-' . $pageName . '.php') != '') {
				get_template_part('woocommerce-food/content-shortcodes/content', $pageName);
			} else {
				$pageName = 'content-' . $pageName;
				$temp_url = exwoof_get_plugin_url().'templates/content-shortcodes/' . $pageName . '.php';
				$temp_url = apply_filters('exwf_default_sctemplate_locate',$temp_url,$pageName);
				include $temp_url;
			}
		}else{
			if (locate_template('woocommerce-food/' . $pageName . '.php') != '') {
				get_template_part('woocommerce-food/'.$pageName);
			} else {
				$temp_url = exwoof_get_plugin_url().'templates/' . $pageName . '.php';
				$temp_url = apply_filters('exwf_default_template_locate',$temp_url,$pageName,$shortcode);
				include $temp_url;
			}
		}
	}
}

if(!function_exists('exwoofood_query')){
    function exwoofood_query($posttype, $count, $order, $orderby, $cat, $tag, $taxonomy, $meta_key, $ids, $meta_value=false,$page=false,$mult=false,$active_filter=false,$feature=false, $sloc = false){
    	if(isset($active_filter) && $active_filter!=''){ $cat = $active_filter;}
		$posttype = 'product';
		if($orderby == 'order_field'){
			$meta_key = 'exwoofood_order';
			$orderby = 'meta_value_num';
		}
		$posttype = explode(",", $posttype);
		
		if($ids!=''){ //specify IDs
			$posttype = array('product','product_variation');
			$ids = explode(",", $ids);
			$args = array(
				'post_type' => $posttype,
				'posts_per_page' => $count,
				'post_status' => array( 'publish'),
				'post__in' =>  $ids,
				'order' => $order,
				'orderby' => $orderby,
				'ignore_sticky_posts' => 1,
			);
		}elseif($ids==''){
			$args = array(
				'post_type' => $posttype,
				'posts_per_page' => $count,
				'post_status' => array( 'publish'),
				'order' => $order,
				'orderby' => $orderby,
				'meta_key' => $meta_key,
				'ignore_sticky_posts' => 1,
			);
			if($orderby =='sale'){
				$ids = array_merge( array( 0 ), wc_get_product_ids_on_sale() );
				if(is_array($ids) && !empty($ids)){
					$args['post__in'] = $ids;
				}
			}
		}

		$loc = WC()->session->get( 'ex_userloc' );
		if(isset($sloc) && $sloc!='' && $sloc!='OFF'){ $loc = $sloc;}
		/*
		if( $tag!=''){
			if($taxonomy ==''){ $taxonomy = 'product_tag';}
			$tags = explode(",",$tag);
			if(is_numeric($tags[0])){$field_tag = 'term_id'; }
			else{ $field_tag = 'slug'; }
			if(count($tags)>1){
				  $texo = array(
					  'relation' => 'OR',
				  );
				  foreach($tags as $iterm) {
					  $texo[] = 
						  array(
							  'taxonomy' => $taxonomy,
							  'field' => $field_tag,
							  'terms' => $iterm,
						  );
				  }
				  if($loc!=''){$texo = array($texo);}
			  }else{
				  $texo = array(
					  array(
							  'taxonomy' => $taxonomy,
							  'field' => $field_tag,
							  'terms' => $tags,
						  )
				  );
			}
		}*/
		//cats
		if($cat!=''){
			//if($taxonomy == '' || ($taxonomy != '' && $tag!='')){$taxonomy = 'product_cat';}
			$cats = explode(",",$cat);
			if(is_numeric($cats[0])){$field = 'term_id'; }
			else{ $field = 'slug'; }
			if(count($cats)>1){
				  $texo = array(
					  'relation' => 'OR',
				  );
				  foreach($cats as $iterm) {
					  $texo[] = 
						  array(
							  'taxonomy' => 'product_cat',
							  'field' => $field,
							  'terms' => $iterm,
						  );
				  }
				  if($loc!=''){$texo = array($texo);}
			  }else{
				  $texo = array(
					  array(
							  'taxonomy' => 'product_cat',
							  'field' => $field,
							  'terms' => $cats,
						  )
				  );
			}
		}

		if( $tag!=''){
			if($taxonomy ==''){ $taxonomy = 'product_tag';}
			$tags = explode(",",$tag);
			if(is_numeric($tags[0])){$field_tag = 'term_id'; }
			else{ $field_tag = 'slug'; }
			if(count($tags)>1){
				  $tag_qr = array(
					  'relation' => 'OR',
				  );
				  foreach($tags as $iterm) {
					  $tag_qr[] = 
						  array(
							  'taxonomy' => $taxonomy,
							  'field' => $field_tag,
							  'terms' => $iterm,
						  );
				  }
				  $tag_qr = array($tag_qr);
			}else{
				$tag_qr = array(
					array(
						'taxonomy' => $taxonomy,
						'field' => $field_tag,
						'terms' => $tag,
					)
				);
			}
			if(!isset($texo) || !is_array($texo)){ $texo = $tag_qr;}
			else{
				$texo['relation'] = 'AND';
				$texo = array_merge($texo, $tag_qr);
			}
			//echo '<pre>';print_r($texo); exit;
		}
		// user select loc
		//check if ( exwoofood_get_option('exwoofood_enable_loc') =='yes' ) {
			if($loc!=''){
				$loc = explode(",",$loc);
				//if(is_numeric($loc[0])){$field = 'term_id'; }
				//else{ $field = 'slug'; }
				$field = 'slug';
				if(!isset($texo) || !is_array($texo)){ $texo = array();}
				$texo['relation'] = 'AND';
				if(count($loc)>1){
					  foreach($loc as $iterm) {
						  $texo[] = 
							  array(
								  'taxonomy' => 'exwoofood_loc',
								  'field' => $field,
								  'terms' => $iterm,
							  );
					  }
				  }else{
					  $texo[] = 
						  array(
								  'taxonomy' => 'exwoofood_loc',
								  'field' => $field,
								  'terms' => $loc,
					  );
				}
			}
		// End check }	
		//if(isset($texo)){
			//$args += array('tax_query' => $texo);
		//}
		if(isset($feature) && $feature==1){
			$args['tax_query']['relation'] = 'AND';
			$args['tax_query'][] = array(
				'taxonomy' => 'product_visibility',
				'field'    => 'name',
				'terms'    => 'featured',
			);
			if(isset($texo)){
				$args['tax_query'][] = $texo;
			}
		}else if(isset($texo)){
			$args['tax_query'] = $texo;
		}
		if(isset($meta_value) && $meta_value!='' && $meta_key!=''){
			if(!empty($args['meta_query'])){
				$args['meta_query']['relation'] = 'AND';
			}
			$args['meta_query'][] = array(
				'key'  => $meta_key,
				'value' => $meta_value,
				'compare' => '='
			);
		}
		if(isset($page) && $page!=''){
			$args['paged'] = $page;
		}
		// Show only post of parent cat
		//foreach ($args['tax_query'] as $key => $value) {
			//$args['tax_query'][$key]['include_children'] = 0;
		//}
		return apply_filters( 'exwoofood_query', $args,$cat );
	}
}

if(!function_exists('exwf_remove_items_outofstock')){
	function exwf_remove_items_outofstock($args){
		if(get_option('woocommerce_hide_out_of_stock_items')=='yes'){
			$args['meta_query']['relation'] = 'AND';
			$args['post_status'] = array( 'publish');
			$args['meta_query']['relation'] = 'AND';
			$args['meta_query'][] = array(
				'key'       => '_stock_status',
				'value'     => 'outofstock',
				'compare'   => 'NOT IN'
			);
		}
		return $args;
	}
}
add_filter( 'exwoofood_query', 'exwf_remove_items_outofstock' );
add_filter( 'exwf_ajax_query_args', 'exwf_remove_items_outofstock' );
add_filter( 'exwf_ajax_filter_query_args', 'exwf_remove_items_outofstock' );

if(!function_exists('EX_WPFood_customlink')){
	function EX_WPFood_customlink($id,$dislbox=false){
		if(isset($dislbox) && $dislbox=='yes') {
			$link = 'javascript:;';
		}else{
			$link = get_the_permalink($id);
		}
		return apply_filters('exwf_prodduct_url',$link,$id);
	}
}
if(!function_exists('exwoofood_page_number_html')){
	if(!function_exists('exwoofood_page_number_html')){
		function exwoofood_page_number_html($the_query,$ID,$atts,$num_pg,$args,$arr_ids){
			if(isset($atts['cat'])){ $atts['cat'] = str_replace(' ', '', $atts['cat']);}
			if(isset($atts['ids'])){ $atts['ids'] = str_replace(' ', '', $atts['ids']);}
			if(function_exists('paginate_links')) {
				echo '<div class="exfd-pagination">';
				echo '
					<input type="hidden"  name="id_grid" value="'.esc_attr($ID).'">
					<input type="hidden"  name="num_page" value="'.esc_attr($num_pg).'">
					<input type="hidden"  name="num_page_uu" value="1">
					<input type="hidden"  name="current_page" value="1">
					<input type="hidden"  name="ajax_url" value="'.esc_url(admin_url( 'admin-ajax.php' )).'">
					<input type="hidden"  name="param_query" value="'.esc_attr(json_encode($args)).'">
					<input type="hidden"  name="param_ids" value="'.esc_attr(json_encode($arr_ids)).'">
					<input type="hidden" id="param_shortcode" name="param_shortcode" value="'.esc_attr(json_encode($atts)).'">
				';
				if($num_pg > 1){
					$page_link =  paginate_links( array(
						'base'         => esc_url_raw( str_replace( 999999999, '%#%', get_pagenum_link( 999999999, false ) ) ),
						'format'       => '?paged=%#%',
						'add_args'     => false,
						'show_all'     => true,
						'current' => max( 1, get_query_var('paged') ),
						'total' => $num_pg,
						'prev_next'    => false,
						'type'         => 'array',
						'end_size'     => 3,
						'mid_size'     => 3
					) );
					$class = '';
					if ( get_query_var('paged')<2) {
						$class = 'disable-click';
					}
					$prev_link = '<a class="prev-ajax '.esc_attr($class).'" href="javascript:;">&larr;</a>';
					$next_link = '<a class="next-ajax" href="javascript:;">&rarr;</a>';
					array_unshift($page_link, $prev_link);
					$page_link[] = $next_link;
					echo '<div class="page-navi">'.wp_kses_post(implode($page_link)).'</div>';
				}
				echo '</div>';
			}
		}
	}
}

if(!function_exists('exwoofood_ajax_navigate_html')){
	function exwoofood_ajax_navigate_html($ID,$atts,$num_pg,$args,$arr_ids){
		echo '
			<div class="ex-loadmore">
				<input type="hidden"  name="id_grid" value="'.esc_attr($ID).'">
				<input type="hidden"  name="num_page" value="'.esc_attr($num_pg).'">
				<input type="hidden"  name="num_page_uu" value="1">
				<input type="hidden"  name="current_page" value="1">
				<input type="hidden"  name="ajax_url" value="'.esc_url(admin_url( 'admin-ajax.php' )).'">
				<input type="hidden"  name="param_query" value="'.esc_attr(json_encode($args)).'">
				<input type="hidden"  name="param_ids" value="'.esc_attr(json_encode($arr_ids)).'">
				<input type="hidden" id="param_shortcode" name="param_shortcode" value="'.esc_attr(json_encode($atts)).'">';
				if($num_pg > 1){
					echo '
					<a  href="javascript:void(0)" class="loadmore-exfood" data-id="'.esc_attr($ID).'">
						<span class="load-text">'.esc_html__('Load more','woocommerce-food').'</span><span></span>&nbsp;<span></span>&nbsp;<span></span>
					</a>';
				}
				echo '
		</div>';
	}
}

add_action( 'wp_ajax_exwoofood_loadmore', 'ajax_exwoofood_loadmore' );
add_action( 'wp_ajax_nopriv_exwoofood_loadmore', 'ajax_exwoofood_loadmore' );
function ajax_exwoofood_loadmore(){
	global $columns,$number_excerpt,$show_time,$orderby,$img_size,$ID;
	global $ID,$number_excerpt,$img_size,$hide_atc;
	$atts = json_decode( stripslashes( $_POST['param_shortcode'] ), true );
	$ID = isset($atts['ID']) && $atts['ID'] !=''? $atts['ID'] : 'ex-'.rand(10,9999);
	$style = isset($atts['style']) && $atts['style'] !=''? $atts['style'] : '1';
	$column = isset($atts['column']) && $atts['column'] !=''? $atts['column'] : '2';
	$posttype   = isset($atts['posttype']) && $atts['posttype']!='' ? $atts['posttype'] : 'product';
	$ids   = isset($atts['ids']) ? $atts['ids'] : '';
	$taxonomy  = isset($atts['taxonomy']) ? $atts['taxonomy'] : '';
	$cat   = isset($atts['cat']) ? $atts['cat'] : '';
	$tag  = isset($atts['tag']) ? $atts['tag'] : '';
	$count   = isset($atts['count']) &&  $atts['count'] !=''? $atts['count'] : '9';
	$posts_per_page   = isset($atts['posts_per_page']) && $atts['posts_per_page'] !=''? $atts['posts_per_page'] : '3';
	$order  = isset($atts['order']) ? $atts['order'] : '';
	$orderby  = isset($atts['orderby']) ? $atts['orderby'] : '';
	$meta_key  = isset($atts['meta_key']) ? $atts['meta_key'] : '';
	$meta_value  = isset($atts['meta_value']) ? $atts['meta_value'] : '';
	$class  = isset($atts['class']) ? $atts['class'] : '';
	$img_size =  isset($atts['img_size']) ? $atts['img_size'] :'';
	$number_excerpt =  isset($atts['number_excerpt'])&& $atts['number_excerpt']!='' ? $atts['number_excerpt'] : '10';
	$page = isset($_POST['page']) ? $_POST['page'] : '';
	$layout = isset($_POST['layout']) ? $_POST['layout'] : '';
	$hide_atc =  isset($atts['hide_atc']) ? $atts['hide_atc'] :'';
	$page_navi  = isset($atts['page_navi']) ? $atts['page_navi'] : '';
	$param_query = json_decode( stripslashes( $_POST['param_query'] ), true );
	$param_ids = '';
	if(isset($_POST['param_ids']) && $_POST['param_ids']!=''){
		$param_ids =  json_decode( stripslashes( $_POST['param_ids'] ), true )!='' ? json_decode( stripslashes( $_POST['param_ids'] ), true ) : explode(",",$_POST['param_ids']);
	}
	$end_it_nb ='';
	if($page!=''){ 
		$param_query['paged'] = $page;
		$count_check = $page*$posts_per_page;
		if(($count_check > $count) && (($count_check - $count)< $posts_per_page)){$end_it_nb = $count - (($page - 1)*$posts_per_page);}
		else if(($count_check > $count)) {die;}
	}
	if(($orderby =='rand' || $meta_key=="_price" ) && is_array($param_ids)){
		$param_query['post__not_in'] = $param_ids;
		$param_query['paged'] = 1;
	}
	if($orderby =='sale'){
		$ids = array_merge( array( 0 ), wc_get_product_ids_on_sale() );
		if(is_array($ids) && !empty($ids)){
			$param_query['post__in'] = $ids;
		}
	}
	$param_query['post_type'] = array('product');
	$param_query['post_status'] = array( 'publish');
	$param_query = apply_filters('exwf_ajax_query_args',$param_query,$atts,$param_ids);
	$the_query = new WP_Query( $param_query );
	$it = $the_query->post_count;
	$html_mnd = '';
	if($page_navi =='' && $layout=='list' && function_exists('exwf_select_date_html')){
		ob_start();
		$enb_mnd =  isset($atts['enb_mnd']) ? $atts['enb_mnd'] :'';
		exwf_select_date_html('',$enb_mnd);
		$html_mnd = ob_get_contents();
		ob_end_clean();
	}
	ob_start();
	if($the_query->have_posts()){
		$i =0;
		$arr_ids = array();
		$html_modal = '';
		while($the_query->have_posts()){ $the_query->the_post();
			global $product;
			$disable_is_visible = apply_filters('exwf_disable_is_visible','no',$product);
			if ($disable_is_visible=='yes' || $product && $product->is_visible() ) {
				$i++;
				$arr_ids[] = get_the_ID();
				if($layout=='table'){
					exwoofood_template_plugin('table-'.$style,1);
				}else if($layout=='list'){
					echo '<div class="fditem-list item-grid" data-id="ex_id-'.esc_attr($ID).'-'.esc_attr(get_the_ID()).'" data-id_food="'.esc_attr(get_the_ID()).'" id="ctc-'.esc_attr($ID).'-'.get_the_ID().'"> ';
						exwf_custom_color('list',$style,'ctc-'.esc_attr($ID).'-'.get_the_ID());
							?>
						<div class="exp-arrow" >
							<?php 
							exwoofood_template_plugin('list-'.$style,1);
							?>
						<div class="exfd_clearfix"></div>
						</div>
						<?php
					echo '</div>';
				}else{
					echo '<div class="item-grid" data-id="ex_id-'.esc_attr($ID).'-'.esc_attr(get_the_ID()).'" data-id_food="'.esc_attr(get_the_ID()).'" id="ctc-'.esc_attr($ID).'-'.get_the_ID().'"> ';
						exwf_custom_color('grid',$style,'ctc-'.esc_attr($ID).'-'.get_the_ID());
						?>
						<div class="exp-arrow">
							<?php 
							exwoofood_template_plugin('grid-'.$style,1);
							?>
						<div class="exfd_clearfix"></div>
						</div>
						<?php
					echo '</div>';
				}
				if($end_it_nb!='' && $end_it_nb == $i){break;}
			}
		}
		wp_reset_postdata();
		
		if(is_array($param_ids) && ($page_navi=='loadmore' || $orderby=='rand')){
			?>
	        <script type="text/javascript">
			jQuery(document).ready(function() {
				jQuery('#<?php  echo esc_html__($_POST['id_crsc']);?> input[name=param_ids]').val(<?php echo str_replace('\/', '/', json_encode(array_merge($param_ids,$arr_ids)));?>);
				setTimeout(function() {
				jQuery('#<?php  echo esc_html__($_POST['id_crsc']);?> .ctgrid > script').each(function () {
				    jQuery(this).remove();
				});
				}, 150);
				var $cr_page = jQuery('#<?php  echo esc_html__($_POST['id_crsc']);?> input[name=current_page]').val();
				if($cr_page > '<?php echo esc_attr($page); ?>'){
					jQuery('#<?php  echo esc_html__($_POST['id_crsc']);?> input[name=param_ids]').val('');
				}
				jQuery('#<?php  echo esc_html__($_POST['id_crsc']);?> input[name=current_page]').val('<?php echo esc_attr($page); ?>');
			});
	        </script>
	        <?php 
		}
        do_action('exwf_after_content_loadmore_html');
	}
	$html = ob_get_clean();
	$html = $html_mnd !='' ? $html_mnd.$html : $html;
	$output =  array('html_content'=>$html,'html_modal'=> $html_modal);
	echo str_replace('\/', '/', json_encode($output));
	die;
}
// register sesion
add_action('woocommerce_init', 'exwf_wc_session_user');
add_action( 'init', 'exwf_wc_session_user' );
function exwf_wc_session_user() {
    if ( is_user_logged_in() || is_admin() )
        return;

    if ( isset(WC()->session) && ! WC()->session->has_session() ) {
        WC()->session->set_customer_session_cookie( true );
    }
}

add_action( 'wp_ajax_exfood_menuegory', 'ajax_exfood_menuegory' );
add_action( 'wp_ajax_nopriv_exfood_menuegory', 'ajax_exfood_menuegory' );
function ajax_exfood_menuegory(){
	global $ID,$number_excerpt,$img_size,$hide_atc;
	$atts = json_decode( stripslashes( $_POST['param_shortcode'] ), true );
	$ID = isset($atts['ID']) && $atts['ID'] !=''? $atts['ID'] : 'ex-'.rand(10,9999);
	$ids   = isset($atts['ids']) ? $atts['ids'] : '';
	$count   = isset($atts['count']) &&  $atts['count'] !=''? $atts['count'] : '9';
	$style = isset($atts['style']) && $atts['style'] !=''? $atts['style'] : '1';
	$posts_per_page   = isset($atts['posts_per_page']) && $atts['posts_per_page'] !=''? $atts['posts_per_page'] : '3';
	$number_excerpt =  isset($atts['number_excerpt'])&& $atts['number_excerpt']!='' ? $atts['number_excerpt'] : '10';
	$cat   = isset($atts['cat']) ? $atts['cat'] : '';
	$tag   = isset($atts['tag']) ? $atts['tag'] : '';
	$taxonomy  = isset($atts['taxonomy']) ? $atts['taxonomy'] : '';
	$orderby   = isset($atts['orderby']) ? $atts['orderby'] : '';
	$page_navi  = isset($atts['page_navi']) ? $atts['page_navi'] : '';
	$img_size =  isset($atts['img_size']) ? $atts['img_size'] :'';
	$featured =  isset($atts['featured']) ? $atts['featured'] :'';
	$hide_atc =  isset($atts['hide_atc']) ? $atts['hide_atc'] :'';
	$page = isset($_POST['page']) ? $_POST['page'] : '';
	$layout = isset($_POST['layout']) ? $_POST['layout'] : '';
	$param_query = json_decode( stripslashes( $_POST['param_query'] ), true );
	$param_ids = '';
	if(isset($_POST['param_ids']) && $_POST['param_ids']!=''){
		$param_ids =  json_decode( stripslashes( $_POST['param_ids'] ), true )!='' ? json_decode( stripslashes( $_POST['param_ids'] ), true ) : explode(",",$_POST['param_ids']);
	}
	$end_it_nb ='';
	if($page!='' && is_numeric($page)){ 
		$param_query['paged'] = $page;
		$count_check = $page*$posts_per_page;
		if(($count_check > $count) && (($count_check - $count)< $posts_per_page)){$end_it_nb = $count - (($page - 1)*$posts_per_page);}
		else if(($count_check > $count)) {die;}
	}
	$param_query['post__in'] ='';
	$loc = '';
	if ( exwoofood_get_option('exwoofood_enable_loc') =='yes' ) {
		$loc = WC()->session->get( 'ex_userloc' );
	}
	$atts_cr = $atts;
	if(isset($_POST['cat']) && $_POST['cat']!=''){
		$atts_cr['cat'] = $_POST['cat'];
		$texo = array(
			array(
				'taxonomy' => 'product_cat',
				'field'    => 'slug',
				'terms'    => $_POST['cat'],
			),
		);
	}else{
		$param_query['tax_query'] ='';
		if($cat!=''){
			//$taxonomy ='product_cat'; 
			$cats = explode(",",$cat);
			if(is_numeric($cats[0])){$field = 'term_id'; }else{ $field = 'slug'; }
			if(count($cats)>1){
				  $texo = array( 'relation' => 'OR');
				  foreach($cats as $iterm) {
					  $texo[] = array(
							  'taxonomy' => 'product_cat',
							  'field' => $field,
							  'terms' => $iterm,
						  );
				  }
				  if($loc!=''){$texo = array($texo);}
			  }else{
				  $texo = array(
					  array(
							  'taxonomy' => 'product_cat',
							  'field' => $field,
							  'terms' => $cats,
						  )
				  );
			}
			
		}
	}
	if( $tag!=''){
		if($taxonomy ==''){ $taxonomy = 'product_tag';}
		$tags = explode(",",$tag);
		if(is_numeric($tags[0])){$field_tag = 'term_id'; }
		else{ $field_tag = 'slug'; }
		if(count($tags)>1){
			  $tag_qr = array(
				  'relation' => 'OR',
			  );
			  foreach($tags as $iterm) {
				  $tag_qr[] = 
					  array(
						  'taxonomy' => $taxonomy,
						  'field' => $field_tag,
						  'terms' => $iterm,
					  );
			  }
			  $tag_qr = array($tag_qr);
		}else{
			$tag_qr = array(
				array(
					'taxonomy' => $taxonomy,
					'field' => $field_tag,
					'terms' => $tag,
				)
			);
		}// 
		if(!isset($texo) || !is_array($texo)){ $texo = $tag_qr;}
		else{
			$texo['relation'] = 'AND';
			$texo = array_merge($texo, $tag_qr);
		}
		//print_r($texo); exit;
	}
	if ( exwoofood_get_option('exwoofood_enable_loc') =='yes' ) {
		if($loc!=''){
			$loc = explode(",",$loc);
			//if(is_numeric($loc[0])){$field = 'term_id'; }
			//else{ $field = 'slug'; }
			$field = 'slug';
			if(!isset($texo) || !is_array($texo)){ $texo = array();}
			$texo['relation'] = 'AND';
			if(count($loc)>1){
				  foreach($loc as $iterm) {
					  $texo[] = 
						  array(
							  'taxonomy' => 'exwoofood_loc',
							  'field' => $field,
							  'terms' => $iterm,
						  );
				  }
			  }else{
				  $texo[] = 
					  array(
							  'taxonomy' => 'exwoofood_loc',
							  'field' => $field,
							  'terms' => $loc,
				  );
			}
		}
	}
	if(isset($texo)){
		$param_query['tax_query'] = $texo;
	}
	if($ids!=''){
		$ids = explode(",", $ids);
		$param_query['post__in'] = $ids;
	}
	if($orderby =='sale'){
		$ids = array_merge( array( 0 ), wc_get_product_ids_on_sale() );
		if(is_array($ids) && !empty($ids)){
			$param_query['post__in'] = $ids;
		}
	}
	if(isset($featured) && $featured==1){
		$param_query['tax_query'][] = array(
			'taxonomy' => 'product_visibility',
			'field'    => 'name',
			'terms'    => 'featured',
		);
	}
	if(isset($_POST['key_word']) && $_POST['key_word']!=''){
		$param_query['s'] = $_POST['key_word'];
	}else{
		$param_query['s'] = '';
	}
	$param_query['post_type'] = array('product');
	$param_query['post_status'] = array( 'publish');
	$param_query = apply_filters('exwf_ajax_filter_query_args',$param_query,$atts_cr);
//print_r($param_query); exit;
	$the_query = new WP_Query( $param_query );
	$it = $the_query->post_count;
	$html_mnd = '';
	if($layout=='list' && function_exists('exwf_select_date_html')){
		ob_start();
		$enb_mnd =  isset($atts['enb_mnd']) ? $atts['enb_mnd'] :'';
		exwf_select_date_html('',$enb_mnd);
		$html_mnd = ob_get_contents();
		ob_end_clean();
	}
	ob_start();
	if($the_query->have_posts()){
		$it = $the_query->found_posts;
		if($it < $count || $count=='-1'){ $count = $it;}
		if($count  > $posts_per_page){
			$num_pg = ceil($count/$posts_per_page);
			$it_ep  = $count%$posts_per_page;
		}else{
			$num_pg = 1;
		}
		$arr_ids = array();
		$html_modal = '';
		$i=0;
		while($the_query->have_posts()){ $the_query->the_post();
			global $product;
			$disable_is_visible = apply_filters('exwf_disable_is_visible','no',$product);
			if ($disable_is_visible=='yes' || $product && $product->is_visible() ) {
				$i++;
				$arr_ids[] = get_the_ID();
				if($layout=='list'){
					echo '<div class="fditem-list item-grid" data-id="ex_id-'.esc_attr($ID).'-'.get_the_ID().'" data-id_food="'.get_the_ID().'" id="ctc-'.esc_attr($ID).'-'.get_the_ID().'"> ';
						exwf_custom_color('list',$style,'ctc-'.esc_attr($ID).'-'.get_the_ID());
							?>
						<div class="exp-arrow" >
							<?php 
							exwoofood_template_plugin('list-'.$style,1);
							?>
						<div class="exfd_clearfix"></div>
						</div>
						<?php
					echo '</div>';
				}elseif($layout=='table'){
					exwoofood_template_plugin('table-'.$style,1);
				}else{
					echo '<div class="item-grid" data-id="ex_id-'.esc_attr($ID).'-'.get_the_ID().'" data-id_food="'.get_the_ID().'" id="ctc-'.esc_attr($ID).'-'.get_the_ID().'"> ';
						exwf_custom_color('grid',$style,'ctc-'.esc_attr($ID).'-'.get_the_ID());
						?>
						<div class="exp-arrow">
							<?php 
							exwoofood_template_plugin('grid-'.$style,1);
							?>
						<div class="exfd_clearfix"></div>
						</div>
						<?php
					echo '</div>';
				}
				if($end_it_nb!='' && $end_it_nb == $i){break;}
			}
		}
		wp_reset_postdata();
	}

	$html = ob_get_contents();
	ob_end_clean();
	$html_dcat = '';
	if($html==''){
		$html = '<span class="exwf-no-rs">'.esc_html__('No matching records found','woocommerce-food').'</span>';
	}else if(isset($_POST['cat']) && $_POST['cat']!=''){
		$term = get_term_by('slug', $_POST['cat'], 'product_cat');
		if($term->description!=''){
			$html_dcat ='<div class="exwf-dcat" style="display:block;">'.$term->description.'</div>';
		}
	}
	$html = $html_mnd !='' ? $html_mnd.$html : $html;
	ob_start();
	// global $modal_html;
	// 	if(!isset($modal_html) || $modal_html!='on'){
	// 		$modal_html = 'on';
	// 		echo "<div id='food_modal' class='ex_modal'></div>";
	// 	}
	if($page_navi=='loadmore'){
		exwoofood_ajax_navigate_html($ID,$atts,$num_pg,$param_query,$arr_ids); 
	}else{
		exwoofood_page_number_html($the_query,$ID,$atts,$num_pg,$param_query,$arr_ids);
	}
	$page_navihtml = ob_get_contents();
	ob_end_clean();
	$output =  array('html_content'=>$html,'page_navi'=> $page_navihtml,'html_modal'=>$html_modal,'html_dcat'=>$html_dcat);
	echo str_replace('\/', '/', json_encode($output));
	die;
}
if(!function_exists('exwoofood_search_form_html')){
	function exwoofood_search_form_html($cats, $order_cat, $pos = false,$active_filter=false,$filter_style=false,$hide_ftall=false,$show_count=false,$echo=false){
		$args = array(
			'hide_empty'        => true,
			'parent'        => '0',
		);
		if($cats !=''){
		    unset($args['parent']);
		}
		$cats = $cats!=''? explode(",",$cats) : array();
		$menucats = function_exists('exwf_menuby_cats_included') ? exwf_menuby_cats_included() : '';
		if(is_array($menucats) && !empty($menucats)){
			//$cats = $menucats;
			if (!empty($cats) && is_numeric($cats[0])) {
				$cats = array_diff($cats,$menucats);
			}else if(empty($cats)){
				$cats = $menucats;
			}
		}
		if (!empty($cats) && !is_numeric($cats[0])) {
			$args['slug'] = $cats;
			$args['orderby'] = 'slug__in';
		}else if (!empty($cats)) {
			$args['include'] = $cats;
			$args['orderby'] = 'include';
		}
		if ($order_cat == 'yes') {
			$args['meta_key'] = 'exwoofood_menu_order';
			$args['orderby'] = 'meta_value_num';
		}
		$loc_selected = exwf_get_loc_selected();
		$exclude = array();
		if($loc_selected!=''){
			$exclude = get_term_meta( $loc_selected, 'exwp_loc_hide_menu', true );
		}
		$count_stop = 5;
		$terms = get_terms('product_cat', $args);
		$css_class = isset($filter_style) && $filter_style=='icon' ? 'exwf-fticon-style' :'';
		$mobile_filter = exwoofood_get_option('exwoofood_mb_filter');
		if($mobile_filter == 'slider' &&  $pos!='left'){
			$css_class .= ' exwf-filter-slider'; 
		}
		$active_filter = isset($active_filter) ? $active_filter :'';
		ob_start();
		?>
        <div class="exfd-filter <?php echo esc_attr($css_class); ?>">
	    	<div class="exfd-filter-group">
	            <?php if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){ 
	            	$select_option = $list_item = '';
	            	
	            	?>
	            	<div class="ex-menu-list">
	            		<?php if (isset($pos) && $pos=='left'){
	            			$act_cls = 'ex-active-left';
	            		}else{
	            			$act_cls = 'ex-menu-item-active';
	            		}
	            		$all_atcl = $act_cls;
	            		if(isset($active_filter) && $active_filter != ''){
	            			$all_atcl = '';	
	            		}
	            		if(isset($hide_ftall) && $hide_ftall!='yes'){?>
		            		<a class="ex-menu-item <?php esc_attr_e($all_atcl);?>" href="javascript:;" data-value=""><?php echo esc_html__('All','woocommerce-food'); ?></a><?php
		            	}
	            			foreach ( $terms as $term ) {
	            				if(($term->count < 1) || is_array($exclude) && !empty($exclude) && in_array($term->slug, $exclude)){
	            					// if exclude
	            				}else{
		            				$all_atcl = '';
		            				global $exwf_child_atv;
		            				$exwf_child_atv = false;
		            				global $wp;
									$curent_url = home_url( $wp->request );
									$curent_url = apply_filters('exwf_current_link',$curent_url);
									ob_start();
									exfd_show_child_inline($cats,$term,$count_stop,$order_cat,'inline',$exclude,$active_filter,$show_count);
									if(isset($active_filter) && $active_filter == $term->slug || $exwf_child_atv==true){
		            					$all_atcl = $act_cls;
		            				}
									$child_c = ob_get_contents();
									ob_end_clean();
							  		echo '<a class="ex-menu-item '.esc_attr($all_atcl).' '.($child_c!='' ? ' exwf-has-child' :'').'" href="'.esc_url(add_query_arg( array('menu' => $term->slug), $curent_url )).'" data-value="'. esc_attr($term->slug) .'">';
								  		if(isset($filter_style) && $filter_style=='icon'){
								  			$_iconsc = get_term_meta( $term->term_id, 'exwoofood_menu_iconsc', true );
								  			if($_iconsc!=''){
								  				echo '<span class="exwf-caticon exwf-iconsc">'.$_iconsc.'</span>'; 
								  			}else{
									  			$thumbnail_id = get_term_meta( $term->term_id, 'thumbnail_id', true );
									  			if($thumbnail_id!=''){
													// get the medium-sized image url
													$image = wp_get_attachment_image_src( $thumbnail_id, 'full' );
													// Output in img tag
													if(isset($image[0]) && $image[0]!=''){
														echo '<span class="exwf-caticon"><img src="' . $image[0] . '" alt="" /></span>'; 
													}
												}
											}
										}
										echo wp_kses_post($term->name);
										if(isset($show_count) && $show_count=='yes'){
											echo '<span class="exwf-cat-count"> ('.$term->count.')</span>'; 
										}
							  			echo $child_c;
							  		echo '</a>';
							  	}
						  	}
						if($mobile_filter != 'slider'){?>
		            		<div class="exfd_clearfix"></div>
		            	<?php }?>
	            	</div>
	            	<div class="ex-menu-select">
	            		<div>
			                <select name="exfood_menu">
			                	<?php if(isset($hide_ftall) && $hide_ftall!='yes'){?>
				                	<option value=""><?php echo esc_html__('All','woocommerce-food'); ?></option>
				                	<?php 
			                	}
		            			foreach ( $terms as $term ) {
		            				if(($term->count < 1) || is_array($exclude) && !empty($exclude) && in_array($term->slug, $exclude)){
	            					// if exclude
	            					}else{
			            				$selected  ='';
			            				if(isset($active_filter) && $active_filter == $term->slug){
			            					$selected  ='selected';
			            				}
			            				$t_count ='';
				        				if(isset($show_count) && $show_count=='yes'){
											$t_count = ' ('.$term->count.')'; 
										}
								  		echo '<option value="'. esc_attr($term->slug) .'" '.esc_attr($selected).'>'. wp_kses_post($term->name) .$t_count.'</option>';
								  		echo exfd_show_child_inline($cats,$term,$count_stop,$order_cat,'',$exclude,$active_filter,$show_count);
								  	}
							  	}
			                	?>
			                </select>
			            </div>
		            </div>
	            <?php } //if have terms ?>
	        </div>
        </div>
        <?php
        $output_string = ob_get_contents();
		ob_end_clean();
		if(isset($echo) && $echo =='no'){
			return $output_string;
		}else{
			echo $output_string;
		}
	}
}

if(!function_exists('exfd_show_child_inline')){
	function exfd_show_child_inline($cats,$term,$count_stop,$order_cat,$inline,$exclude=false,$active_filter=false,$show_count=false){
		global $exwf_child_atv;
		if ($count_stop < 2) {
			return;
		}
		$charactor ='';
		if ($count_stop == 5) {
			$charactor ='— ';
		}elseif ($count_stop == 4) {
			$charactor ='—— ';
		}elseif ($count_stop == 3) {
			$charactor ='——— ';
		}elseif ($count_stop == 2) {
			$charactor ='———— ';
		}
		$args_child = array(
				'child_of' => $term->term_id,
				'parent' => $term->term_id,
				'hide_empty'        => true,
		);
		if ($order_cat == 'yes') {
			$args_child['meta_key'] = 'exwoofood_menu_order';
			$args_child['orderby'] = 'meta_value_num';
		}
		$active_filter = isset($active_filter) ? $active_filter :'';
		$show_count = isset($show_count) ? $show_count :'';
		$show_count = apply_filters('exwf_show_count_child_cat',$show_count);
		$second_level_terms = get_terms('product_cat', $args_child);
		if ($second_level_terms) {
			$count_stop = $count_stop -1;
			if ($inline != 'inline') {
				foreach ($second_level_terms as $second_level_term) {
					if(($second_level_term->count < 1) || is_array($exclude) && !empty($exclude) && in_array($second_level_term->slug, $exclude)){
					// if exclude
					}else{
						$selected  ='';
        				if(isset($active_filter) && $active_filter == $second_level_term->slug){
        					$selected  ='selected';
        					//$exwf_child_atv = true;
        				}
        				$t_count ='';
        				if(isset($show_count) && $show_count=='yes'){
							$t_count = ' ('.$second_level_term->count.')'; 
						}
						echo '<option value="'. esc_attr($second_level_term->slug) .'" '.esc_attr($selected).'>'.wp_kses_post($charactor. $second_level_term->name) .$t_count.'</option>';
						exfd_show_child_inline($cats,$second_level_term,$count_stop,$order_cat,'','',$active_filter,$show_count);
					}
				}
			}else{
				echo '<span class="exfd-caret"></span>';
		        echo '<ul class="exfd-ul-child">';
		        global $wp;
				$curent_url = home_url( $wp->request );
				$curent_url = apply_filters('exwf_current_link',$curent_url);
		        foreach ($second_level_terms as $second_level_term) {
		        	if(($second_level_term->count < 1) || is_array($exclude) && !empty($exclude) && in_array($second_level_term->slug, $exclude)){
					// if exclude
					}else{
			            $second_term_name = $second_level_term->name;
			            $atcl = '';
        				if(isset($active_filter) && $active_filter == $second_level_term->slug){
        					$atcl = 'ex-menu-item-active';
        					$exwf_child_atv = true;
        				}
						$t_count ='';
        				if(isset($show_count) && $show_count=='yes'){
							$t_count = '<span class="exwf-cat-count"> ('.$second_level_term->count.')</span>'; 
						}				
			            echo '<li class="exfd-child-click ex-menu-item '.esc_attr($atcl).'" data-value="'.esc_attr($second_level_term->slug).'" data-url="'.esc_url(add_query_arg( array('menu' => $second_level_term->slug), $curent_url )).'">
			            '.wp_kses_post($second_term_name).$t_count;
			            exfd_show_child_inline($cats,$second_level_term,$count_stop,$order_cat,'inline','',$active_filter,$show_count);
			            echo '</li>';
			        }
		        }

		        echo '</ul>';
		    }
	    }
	}
}

function exwoofood_convert_color($color){
	if ($color == '') {
		return;
	}
	$hex  = str_replace("#", "", $color);
	if(strlen($hex) == 3) {
	  $r = hexdec(substr($hex,0,1).substr($hex,0,1));
	  $g = hexdec(substr($hex,1,1).substr($hex,1,1));
	  $b = hexdec(substr($hex,2,1).substr($hex,2,1));
	} else {
	  $r = hexdec(substr($hex,0,2));
	  $g = hexdec(substr($hex,2,2));
	  $b = hexdec(substr($hex,4,2));
	}
	$rgb = $r.','. $g.','.$b;
	return $rgb;
}

if(!function_exists('exwoofood_sale_badge')){
	function exwoofood_sale_badge(){
		global $product;
		if ( is_object($product) && method_exists($product, 'is_on_sale') && $product->is_on_sale() ) { ?>
			<div class="exfd-ribbon exwf-sale-bg"><span><?php esc_html_e('Sale','woocommerce-food');?></span></div>
			<?php 
		}elseif(exfd_show_reviews('',$product)!=''){
			echo '<div class="exfd-ribbon exwf-review-bg"><span>'.exfd_show_reviews('',$product).'</span></div>';
		}
	}
}

if(!function_exists('exwoofood_add_to_cart_form_shortcode')){
	function exwoofood_add_to_cart_form_shortcode( $atts ) {
		global $cart_itemkey;
		$cart_itemkey = isset($atts['exwf_cart_itemkey']) ? $atts['exwf_cart_itemkey'] : '';
		if (!exwf_check_open_close_time($atts['id'])) {
			return exwfd_open_closing_message();
		}
		$hide_pm = isset( $atts['hide_pm']) ? $atts['hide_pm'] : '';

		if ( empty( $atts ) || !function_exists('woocommerce_template_single_add_to_cart')) { return '';}
		if ( ! isset( $atts['id'] ) && ! isset( $atts['sku'] ) ) { return '';}
		$args = array(
			'posts_per_page'      => 1,
			'post_type'           => 'product',
			'post_status'         => 'publish',
			'ignore_sticky_posts' => 1,
			'no_found_rows'       => 1,
		);
		if ( isset( $atts['sku'] ) ) {
			$args['meta_query'][] = array(
				'key'     => '_sku',
				'value'   => sanitize_text_field( $atts['sku'] ),
				'compare' => '=',
			);
			$args['post_type'] = array( 'product', 'product_variation' );
		}
		if ( isset( $atts['id'] ) ) {
			$args['p'] = absint( $atts['id'] );
		}
		// Change form action to avoid redirect.
		add_filter( 'woocommerce_add_to_cart_form_action', '__return_empty_string' );
		$single_product = new WP_Query( $args );
		$preselected_id = '0';
		global $wp_food;
		$wp_food = 'woo';
		// Check if sku is a variation.
		if ( isset( $atts['sku'] ) && $single_product->have_posts() && 'product_variation' === $single_product->post->post_type ) {
			$variation = new WC_Product_Variation( $single_product->post->ID );
			$attributes = $variation->get_attributes();
			// Set preselected id to be used by JS to provide context.
			$preselected_id = $single_product->post->ID;
			// Get the parent product object.
			$args = array(
				'posts_per_page'      => 1,
				'post_type'           => 'product',
				'post_status'         => 'publish',
				'ignore_sticky_posts' => 1,
				'no_found_rows'       => 1,
				'p'                   => $single_product->post->post_parent,
			);
			$single_product = new WP_Query( $args );
			?>
			<script type="text/javascript">
				jQuery( document ).ready( function( $ ) {
					var $variations_form = $( '[data-product-page-preselected-id="<?php echo esc_attr( $preselected_id ); ?>"]' ).find( 'form.variations_form' );
					<?php foreach ( $attributes as $attr => $value ) { ?>
						$variations_form.find( 'select[name="<?php echo esc_attr( $attr ); ?>"]' ).val( '<?php echo esc_js( $value ); ?>' );
					<?php } ?>
				});
			</script>
		<?php
		}
		// For "is_single" to always make load comments_template() for reviews.
		$single_product->is_single = false;
		ob_start();
		global $wp_query;
		// Backup query object so following loops think this is a product page.
		$previous_wp_query = $wp_query;
		$wp_query          = $single_product;
		wp_enqueue_script( 'wc-single-product' );
		while ( $single_product->have_posts() ) {
			$single_product->the_post();
			$_sold_individually = get_post_meta( get_the_ID(), '_sold_individually', true );?>
			<div class="single-product exwf-sold_indiv-<?php echo esc_attr($_sold_individually); ?>" data-product-page-preselected-id="<?php echo esc_attr( $preselected_id ); ?>">
				<?php woocommerce_template_single_add_to_cart();
				do_action('exwf_after_atc_form');
				if($hide_pm!='1'){?>
					<input type="hidden" name="exwf-primg" value="<?php echo wp_get_attachment_url( get_post_thumbnail_id(get_the_ID()) ); ?>">
					<script type="text/javascript">
						<?php 
						if($_sold_individually!='yes'){
							?>
							jQuery(document).ready(function() {
								jQuery( '#food_modal .exwoofood-woocommerce .cart div.quantity:not(.exbuttons_added):not(.hidden)' ).addClass( 'exbuttons_added' ).append( '<input type="button" value="+" id="exadd_ticket" class="explus" />' ).prepend( '<input type="button" value="-" id="exminus_ticket" class="exminus" />' );
							});
						<?php }?>
						if ( typeof exwf_change_img == 'function' ) {
						}else{
							function exwf_change_img(){
								if(jQuery('.ex_modal .exwf-md-modern.modal-content').length){ return;}
								var defimg = '';
								/*jQuery( ".single_variation_wrap" ).on( "show_variation", function ( event, variation ) {
									if(variation.image.src!=''){
										console.log(variation.image.src);
										jQuery('#food_modal .fd_modal_img').html('');
									}
								} );*/
								jQuery( document ).on( "found_variation.first", function ( e, variation ) {
									var img_pr = jQuery('#food_modal input[name=exwf-primg]').val();
									if(variation.image.full_src!='' && variation.image.full_src!= undefined ){
										jQuery('#food_modal .fd_modal_img .exwf-vari-img').fadeOut("normal", function() {
									        jQuery(this).remove();
									    });
										jQuery('#food_modal .fd_modal_img').prepend('<div class="exwf-vari-img"><img src="'+variation.image.full_src+'"/></div>').fadeIn('normal');
									}
								} );
								jQuery("body").on( "woocommerce_variation_select_change", ".variations_form" , function () {
								    setTimeout(function(){
										var $_cr_img = jQuery('#food_modal .exwoofood-woocommerce form.variations_form').attr("current-image");
								    	if($_cr_img==''){
								    		jQuery('#food_modal .fd_modal_img .exwf-vari-img').remove();
								    		jQuery('#food_modal .exfd-modal-carousel:not(.exwp-no-galle)').EX_ex_s_lick('setPosition');
								    	}
									}, 500);
								} );
							}
							exwf_change_img();
						}	
					</script>
				<?php 
				}?>
			</div>
			<?php
		}
		// Restore $previous_wp_query and reset post data.
		$wp_query = $previous_wp_query;
		wp_reset_postdata();
		return '<div class="exwoofood-woocommerce woocommerce">' . ob_get_clean() . '</div>';
	}
}
add_shortcode( 'ex_food_wooform', 'exwoofood_add_to_cart_form_shortcode' );

add_action( 'wp_ajax_exwoofood_booking_info', 'ajax_exwoofood_booking_info' );
add_action( 'wp_ajax_nopriv_exwoofood_booking_info', 'ajax_exwoofood_booking_info' );

function ajax_exwoofood_booking_info(){
	if(isset($_POST['id_food']) && $_POST['id_food']!=''){
		if ( get_post_type( $_POST['id_food'] ) == 'product_variation' ) {
			$parent_id = wp_get_post_parent_id( $_POST['id_food'] );
			$_POST['id_food'] = $parent_id;
		}
		$product_exist = $_POST['id_food'];
		global $atts,$id_food,$param_shortcode,$exwf_itemkey;
		$atts['exwf_cart_itemkey'] = isset($_POST['cart_itemkey']) ? $_POST['cart_itemkey'] : '';
		$param_shortcode = isset($_POST['param_shortcode']) ? $_POST['param_shortcode'] : '';
		$param_shortcode = json_decode( stripslashes( $param_shortcode ), true );
		$id_food = $_POST['id_food'];
        if($product_exist!='' && is_numeric($product_exist)){
			$atts['id'] = $product_exist;
		}
		exwoofood_template_plugin('modal',true);
	}else{
		echo 'error';
	}
	exit;	
}
function exwf_get_error_notices(){
	return array( 'error');
}
add_action('wp_ajax_exwoofood_add_to_cart', 'exwoofood_ajax_add_to_cart');
add_action('wp_ajax_nopriv_exwoofood_add_to_cart', 'exwoofood_ajax_add_to_cart');
function exwoofood_ajax_add_to_cart() {
	do_action('exwf_before_ajaxadd_to_cart',$_POST);
	/*$product_id = apply_filters('woocommerce_add_to_cart_product_id', absint($_POST['add-to-cart']));
    $quantity = empty($_POST['quantity']) ? 1 : wc_stock_amount($_POST['quantity']);
    $variation_id = absint($_POST['variation_id']);
    $passed_minmax = apply_filters('exwf_add_to_cart_validation_minmax', true, $product_id, $quantity,$variation_id,'');
    if($passed_minmax==false){
    	$data = array(
            'error' => true,
            'message' => '<p class="exfd-out-notice">'.wc_print_notices( true).'</p>'
        );
        wc_clear_notices();
        echo wp_send_json($data);
        wp_die();
    }
    $passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, $quantity,$variation_id);
    $product_status = get_post_status($product_id);
    $un_vali = apply_filters( 'exwfood_remove_atc_valid', false );
    if ($passed_validation || $un_vali == true) {

        do_action('woocommerce_ajax_added_to_cart', $product_id);

        if ('yes' === get_option('woocommerce_cart_redirect_after_add')) {
            wc_add_to_cart_message(array($product_id => $quantity), true);
        }

        WC_AJAX :: get_refreshed_fragments();
    } else {

        $data = array(
            'error' => true,
            'message' => '<div class="exfd-out-notice">'.wc_print_notices( true).'</div>'
        );
        wc_clear_notices();
        echo wp_send_json($data);
    }*/
    add_filter('woocommerce_notice_types', 'exwf_get_error_notices');
    $notice = wc_print_notices( true);
    if($notice!=''){
    	$data = array(
            'error' => true,
            'message' => '<div class="exfd-out-notice">'.$notice.'</div>'
        );
        wc_clear_notices();
        echo wp_send_json($data);
    }
    //WC_AJAX :: get_refreshed_fragments();
    wp_die();
}
add_action('wp_ajax_exwoofood_refresh_cart', 'exwoofood_refresh_cart');
add_action('wp_ajax_nopriv_exwoofood_refresh_cart', 'exwoofood_refresh_cart');
function exwoofood_refresh_cart() {
	WC_AJAX :: get_refreshed_fragments();
	wp_die();
}

/*--- Booking button ---*/
if(!function_exists('exwoofood_booking_button_html')){
	function exwoofood_booking_button_html($style,$hide_atc=false) {
		if (!exwf_check_open_close_time(get_the_ID()) || (isset($hide_atc) && $hide_atc=='yes' ) ) {
			return;
		}
		global $exwf_imlqty;
		$exwf_imlqty = apply_filters('exwf_show_inline_qty','yes');
		global $hide_total;
		$hide_total ='yes';
		$order_text = apply_filters('exwf_order_button_text',esc_html__( 'Order', 'woocommerce-food' ));
		$html = '<a href="'.get_the_permalink(get_the_ID()).'" class="exstyle-'.esc_attr($style).'-button">'.$order_text.'</a>';
		include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
        $product_exist = get_the_ID();
    	$product = wc_get_product ($product_exist);
    	if($product!==false) {
    		if(!$product->is_in_stock()){ return;}
        	$type = $product->get_type();
        	$disable_addon = apply_filters( 'exwf_disable_default_options', 'no' );
        	$disable_atc = apply_filters( 'exwf_disable_add_to_cart', 'no' );
        	if($type =='variable' || $disable_atc =='yes'){

        	}else if(function_exists('exwoo_get_options') && $disable_addon!='yes'){
        		$data_options = exwoo_get_options($product_exist);
        		$ck_buin = 0;
        		if(is_array($data_options) && !empty($data_options)){

        		}else{
	        		if($type =='simple' && is_array($data_options) && empty($data_options) || $type =='simple' && $data_options =='' ){
	        			$html = do_shortcode( '[ex_food_wooform id="'.$product_exist.'" hide_pm="1"]');
	        		}else{$ck_buin = 1;}
	        		if (is_plugin_active( 'woocommerce-tm-extra-product-options/tm-woo-extra-product-options.php' ) ) {
	        			$has_epo = THEMECOMPLETE_EPO_API()->has_options($product_exist );

						if ( THEMECOMPLETE_EPO_API()->is_valid_options( $has_epo ) ) {
							$html = '<a href="'.get_the_permalink($product_exist).'" class="exstyle-'.esc_attr($style).'-button">'.esc_html__( 'Order', 'woocommerce-food' ).'</a>';
	        			}else{
	        				$html = do_shortcode( '[ex_food_wooform id="'.$product_exist.'" hide_pm="1"]');
	        			}
						
					}
					if ($ck_buin!='1' &&  is_plugin_active( 'woocommerce-product-addons/woocommerce-product-addons.php' ) ) {
						if(function_exists('get_product_addons')){
							$product_addons = get_product_addons( $product_exist, false );
						}else{
							$product_addons = WC_Product_Addons_Helper::get_product_addons( $product_exist );
							wp_enqueue_script( 'jquery-tiptip', WC()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip.min.js', array( 'jquery' ), WC_VERSION, true );
						}
						if ( is_array( $product_addons ) && sizeof( $product_addons ) > 0 ) {
							$html = '<a href="'.get_the_permalink($product_exist).'" class="exstyle-'.esc_attr($style).'-button">'.esc_html__( 'Order', 'woocommerce-food' ).'</a>';
						}else if($type =='simple'){
							$html = do_shortcode( '[ex_food_wooform id="'.$product_exist.'" hide_pm="1"]');
						}
					}
				}
        	}else if (is_plugin_active( 'woocommerce-product-addons/woocommerce-product-addons.php' ) ) {
				if(function_exists('get_product_addons')){
					$product_addons = get_product_addons( $product_exist, false );
				}else{
					$product_addons = WC_Product_Addons_Helper::get_product_addons( $product_exist );
					wp_enqueue_script( 'jquery-tiptip', WC()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip.min.js', array( 'jquery' ), WC_VERSION, true );
				}
				if ( is_array( $product_addons ) && sizeof( $product_addons ) > 0 ) {
				}else if($type =='simple'){
					$html = do_shortcode( '[ex_food_wooform id="'.$product_exist.'" hide_pm="1"]');
				}
			}else if (is_plugin_active( 'woocommerce-tm-extra-product-options/tm-woo-extra-product-options.php' ) ) {
				// alway open lightbox
			}else if($type =='simple'){
				$html = do_shortcode( '[ex_food_wooform id="'.$product_exist.'" hide_pm="1"]');
			}
		}
		//inline button
		echo '<div class="exbt-inline '.($exwf_imlqty=='yes' ? ' exwf-show-inlgty' :'').'">'.$html.'</div>';
		$exwf_imlqty='';
		
	}
}

add_filter( 'woocommerce_add_to_cart_fragments', 'exwoofood_woo_cart_count_fragments', 10, 1 );
function exwoofood_woo_cart_count_fragments( $fragments ) {
    $fragments['span.exfd-cart-num'] = '<span class="exfd-cart-num">' . WC()->cart->get_cart_contents_count() . '</span>';
    
    return $fragments;
}

add_filter( 'woocommerce_add_to_cart_fragments', 'exwoofood_woo_cart_content_fragments', 10, 1 );
function exwoofood_woo_cart_content_fragments( $fragments ) {
    ob_start();?>
    <div class="exfd-cart-mini"><?php woocommerce_mini_cart(); ?></div>
    <?php
    $fragments['div.exfd-cart-mini'] = ob_get_contents();
    ob_get_clean();
    return $fragments;
}
// exfood price
function exwoofood_price_with_currency($id_food=false){
	global $product;
	if(isset($id_food) && is_numeric($id_food)){
		$product = wc_get_product ($id_food);
	}
	//$type = $product->get_type();
	$price ='';
	if ( $price_html = $product->get_price_html() ) :
		$price = $price_html; 
	endif; 	
	return $price;
}
function exwoofood_woo_cart_icon_html($show){
	global $cart_icon;
	if(!isset($cart_icon) || $cart_icon!='on' || $show='yes'){
		$cart_icon = 'on';
	}else if($cart_icon =='on'){
		return;
	}
	if(!function_exists('woocommerce_mini_cart')){ return;}
	ob_start();
	exwoofood_template_plugin('cart-mini',1);
	$output_string = ob_get_contents();
	ob_end_clean();
	return $output_string;
}

function exwoofood_select_loc_html($atts){
	$locations = isset($atts['locations']) ? $atts['locations'] : '';
	$args = array(
		'hide_empty'        => true,
		'parent'        => '0',
	);
	$locations = $locations!='' ? explode(",",$locations) : array();
	if (!empty($locations) && !is_numeric($locations[0])) {
		$args['slug'] = $locations;
	}else if (!empty($locations)) {
		$args['include'] = $locations;
	}
	$args = apply_filters('exwf_location_args',$args);
	$terms = get_terms('exwoofood_loc', $args);
	ob_start();
	$loc_selected = isset(WC()->session) ? WC()->session->get( 'ex_userloc' ) : '';
	?>
	<div class="exwoofood-select-loc">
		<div>
			<select class="ex-loc-select" data-text="<?php esc_html_e('The products added to cart for this location will reset. Are you sure you want to change the location ?','woocommerce-food');?>">
				<?php if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
					global $wp;
					$cr_url =  home_url( $wp->request );
					$cr_url = apply_filters('exwf_current_link',$cr_url);
		        	$select_option = '';
		        	echo  '<option disabled selected value>'.esc_html__( '-- Select --', 'woocommerce-food' ) .'</option>';
		        	$count_stop = 5;
		        	foreach ( $terms as $term ) {
		        		$url = add_query_arg(array('loc' => $term->slug), $cr_url);
		        		$selected = $loc_selected == $term->slug ? 'selected' : '';
				  		echo '<option value="'. esc_url($url) .'" '.esc_attr($selected).' >'. wp_kses_post($term->name) .'</option>';
				  		exfd_show_child_location($locations,$term,$count_stop,$loc_selected,'');
				  	}
		        } //if have terms ?>
			</select>
		</div>
	</div>
	<?php
	$cart_content = ob_get_contents();
	ob_end_clean();
	return $cart_content;
}
add_shortcode( 'exwoofood_sllocation', 'exwoofood_select_loc_html' );
if(!function_exists('exfd_show_child_location')){
	function exfd_show_child_location($locations,$term,$count_stop,$loc_selected,$checkout,$s_all=false){
		if ($count_stop < 2) {
			return;
		}
		$charactor ='';
		if ($count_stop == 5) {
			$charactor ='— ';
		}elseif ($count_stop == 4) {
			$charactor ='—— ';
		}elseif ($count_stop == 3) {
			$charactor ='——— ';
		}elseif ($count_stop == 2) {
			$charactor ='———— ';
		}
		$args_child = array(
				'child_of' => $term->term_id,
				'parent' => $term->term_id,
				'hide_empty'        => false,
		);
		$args_child = apply_filters('exwf_location_args',$args_child);
		if(isset($s_all) && $s_all==true){$args_child['exclude']='';}else{ $s_all='';}
		$second_level_terms = get_terms('exwoofood_loc', $args_child);
		$loc_current = '';
		/*if (isset($_SESSION['exfd_data_check']) && $_SESSION['exfd_data_check']!='') {
			$data_order = array();
			$data_order = $_SESSION['exfd_data_check'];
			$loc_current = isset($data_order['_location']) ? $data_order['_location'] : '';
		}*/
		ob_start();
		if ($second_level_terms) {
			$count_stop = $count_stop -1;
			foreach ($second_level_terms as $second_level_term) {
				$addres_log = get_term_meta( $second_level_term->term_id, 'exwp_loc_address', true );
				$addres_latlong = get_term_meta( $second_level_term->term_id, 'exwp_loc_address_lat_long', true );
				$ct_attr = apply_filters('exwf_loc_ctattr',$second_level_term->term_id,$second_level_term);
				if ($checkout !='yes') {
					global $wp;
					$cr_url =  home_url( $wp->request );
					$cr_url = apply_filters('exwf_current_link',$cr_url);
					$url = add_query_arg(array('loc' => $second_level_term->slug), $cr_url);
	        		$selected = $loc_selected == $second_level_term->slug ? 'selected' : '';
			  		echo '<option value="'. esc_url($url) .'" '.esc_attr($selected).' data-addr="'.esc_attr($addres_log).'" data-latlng="'.esc_attr($addres_latlong).'" '.$ct_attr.'>'.$charactor. wp_kses_post($second_level_term->name) .'</option>';
				}else{
					$select_loc = '';
	        		if ($second_level_term->slug !='' && $second_level_term->slug == $loc_selected) {
		                $select_loc = ' selected="selected"';
		              }
					echo '<option value="'. esc_attr($second_level_term->slug) .'" '.$select_loc.' data-addr="'.esc_attr($addres_log).'" data-latlng="'.esc_attr($addres_latlong).'" '.$ct_attr.'>'.$charactor. wp_kses_post($second_level_term->name) .'</option>';
				}
				
				exfd_show_child_location($locations,$second_level_term,$count_stop,$loc_selected,$checkout,$s_all);
			}
	    }
	    $output_string = ob_get_contents();
		ob_end_clean();
		if($checkout =='yes'){
			return $output_string;
		}else{
			echo $output_string;
		}
	}
}
function exwoofood_select_location_html($locations){
	if ( exwoofood_get_option('exwoofood_enable_loc') !='yes' ) {
		return;
	}
	$loc_selected = WC()->session->get( 'ex_userloc' );
	if($loc_selected!=''){
		return;
	}
	global $args_sc;
	$enable_slloc = isset($args_sc['enable_slloc']) ? $args_sc['enable_slloc'] : '';
	if($enable_slloc!='yes'){
		global $loc_exits;
		if(!isset($loc_exits) || $loc_exits!='on'){
			$loc_exits = 'on';
		}else if($loc_exits =='on'){
			return;
		}
	}
	$atts = array();
	$atts['locations'] = $locations;
	?>
	<div class="ex-popup-location">
		<div class="ex-popup-content">
			<?php
			$icon = exwoofood_get_option('exwoofood_loc_icon');
			if($icon!=''){ ?>
				<div class="ex-pop-icon">
					<img src="<?php echo esc_url($icon);?>" alt="image">
				</div>
			<?php } ?>
			<div class="ex-popup-info">
				<h1><?php esc_html_e('Please choose area you want to order','woocommerce-food');?></h1>
				<?php echo exwoofood_select_loc_html($atts); ?>
			</div>
		</div>
	
	</div>
	<?php
}
add_action( 'init', 'exwoofood_user_select_location',20 );
function exwoofood_user_select_location(){
	if(is_admin()&& !defined( 'DOING_AJAX' ) || !isset(WC()->session) ){ return;}
	if(isset($_GET["loc"])){
		$term = term_exists( $_GET["loc"], 'exwoofood_loc' );
		if ( $term !== 0 && $term !== null ) {
			$ex_userloc = WC()->session->get( 'ex_userloc' );
			if($ex_userloc=='' || $ex_userloc != $_GET["loc"]){
			//if(!isset($_SESSION['ex_userloc']) || $_SESSION['ex_userloc'] != $_GET["loc"]){
				if ( exwoofood_get_option('exwoofood_enable_loc') =='yes' ) {
					global $woocommerce;
					$woocommerce->cart->empty_cart();
				}
				WC()->session->set( 'ex_userloc' , $_GET["loc"]);
				if(WC()->session->get( '_user_deli_log' )==''){
					WC()->session->set( '_user_deli_log', $_GET["loc"] );
				}
				//$_SESSION['ex_userloc'] = $_GET["loc"];
				//session_write_close();
			}
		}else{
			WC()->session->set( 'ex_userloc' , '');
			//$_SESSION['ex_userloc'] = '';
			//session_write_close();
		}
	}
	if ( exwoofood_get_option('exwoofood_enable_loc') !='yes' ) {
		WC()->session->set( 'ex_userloc' , '');
		//$_SESSION['ex_userloc'] = '';
		//session_write_close();
	}
}

function exwoofood_location_field_html(){
	$args = array(
		'hide_empty'        => true,
		'parent'        => '0',
	);
	$args = apply_filters('exwf_location_args',$args);
	$terms = get_terms('exwoofood_loc', $args);
	ob_start();
	$loc_selected = WC()->session->get( 'ex_userloc' );
	$loc_current = '';
	/*
	if (isset($_SESSION['exfd_data_check']) && $_SESSION['exfd_data_check']!='') {
		$data_order = array();
		$data_order = $_SESSION['exfd_data_check'];
		$loc_current = isset($data_order['_location']) ? $data_order['_location'] : '';
	}*/
	?>
	<select class="ex-ck-select exfd-choice-locate" name="_location">
		<?php if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
			global $wp;
			if ( exwoofood_get_option('exwoofood_enable_loc') !='yes' ) {
	        	$select_option = '';
	        	$count_stop = 5;
	        	echo '<option disabled selected value>'.esc_html__( '-- Select --', 'woocommerce-food' ) .'</option>';
	        	foreach ( $terms as $term ) {
	        		$select_loc = '';
	        		if ($term->slug !='' && $term->slug == $loc_current) {
		                $select_loc = ' selected="selected"';
		              }
			  		echo '<option value="'. esc_attr($term->slug) .'" '.$select_loc.'>'. wp_kses_post($term->name) .'</option>';
			  		exfd_show_child_location('',$term,$count_stop,$loc_selected,'yes');
			  	}
			}else{
				$term = get_term_by('slug', $loc_selected, 'exwoofood_loc');
				echo '<option selected value="'.esc_attr( $loc_selected ).'">'.wp_kses_post($term->name).'</option>';
			}
        } //if have terms ?>
	</select>
	<?php
	$loca = ob_get_contents();
	ob_end_clean();
	return $loca;
}

add_action( 'wp_ajax_exwoofood_loadstore', 'ajax_exwoofood_loadstore' );
add_action( 'wp_ajax_nopriv_exwoofood_loadstore', 'ajax_exwoofood_loadstore' );
function ajax_exwoofood_loadstore(){
	
	$param_query = json_decode( stripslashes( $_POST['param_query'] ), true );
	$locate_param = '';
	$locate_param = sanitize_text_field($_POST['locate_param']);
	if ($locate_param == '') {
		return;
	}
	ob_start();
	$posts_array = get_posts(
        array(
            'post_status' => array( 'publish'),
            'post_type' => 'exwoofood_store',
            'tax_query' => array(
                array(
                    'taxonomy' => 'exwoofood_loc',
                    'field' => 'slug',
                    'terms' => $locate_param,
                )
            )
        )
    );
    
    $count =sizeof($posts_array);
    if ($count == 0) {
    	echo "0";
    }else{
	    echo '<label class="exfd-label">'.esc_html__("Select store","woocommerce-food").'</label>';
	    $number = 1;
	    $check='';
		foreach ( $posts_array as $it ) {
			if ($number == 1) {
				$check ='checked="checked"';
			}else{$check ='';}
			$number = $number + 1;
			echo '<label class="exfd-container"><p>'.wp_kses_post($it->post_title).'</p>
				<span>'.wpautop($it->post_content).'</span>
				<input class="exfd-choice-order" type="radio" name="_store" '.$check.' value="'.esc_attr($it->ID).'">
				<span class="exfd-checkmark"></span>
	        </label>';
		}
	}
	$html = ob_get_clean();
	$output =  array('html_content'=>$html);
	echo str_replace('\/', '/', json_encode($output));
	die;
}


if(!function_exists('exwoofood_pagenavi_no_ajax')){
	function exwoofood_pagenavi_no_ajax($the_query){
		if(function_exists('paginate_links')) {
			echo '<div class="exwoofood-no-ajax-pagination">';
			echo paginate_links( array(
				'base'         => esc_url_raw( str_replace( 999999999, '%#%', get_pagenum_link( 999999999, false ) ) ),
				'format'       => '',
				'add_args'     => false,
				'current' => max( 1, get_query_var('paged') ),
				'total' => $the_query->max_num_pages,
				'prev_text'    => '&larr;',
				'next_text'    => '&rarr;',
				'type'         => 'list',
				'end_size'     => 3,
				'mid_size'     => 3
			) );
			echo '</div>';
		}
	}
}

if(!function_exists('exwfd_get_current_time')){
	function exwfd_get_current_time(){
		$cure_time =  strtotime("now");
		$gmt_offset = exwf_df_gmt_offset();
		if($gmt_offset!=''){
			$cure_time = $cure_time + ($gmt_offset*3600);
		}
		return $cure_time;
	}
}
// get location selected
if(!function_exists('exwf_get_loc_selected')){
	function exwf_get_loc_selected(){
		$loc_selected = WC()->session->get( 'ex_userloc' );
		// if enable food by loc
		if($loc_selected !='' && isset($_POST['action']) && $_POST['action']=='exwf_check_distance' && isset($_POST['log']) && $_POST['log']!=''){
			$loc_selected = sanitize_text_field($_POST['log']);
		}
		$user_log = '';
		if($loc_selected==''){
			$user_log = WC()->session->get( '_user_deli_log' );
			$loc_selected=  $user_log ;
		}
		if($loc_selected!=''){
			$term = get_term_by('slug', $loc_selected, 'exwoofood_loc');
			if(isset($term->term_id)){
				return $term->term_id;
			}
		}
		return;
	}
}
if(!function_exists('exwf_check_open_close_time')){
	function exwf_check_open_close_time($id_cr=false){
		$enable_time = exwoofood_get_option('exwoofood_open_close','exwoofood_advanced_options');
		if($enable_time=='closed'){
			return false;
		}
		$check_pr = false;
		if(isset($id_cr) && is_numeric($id_cr)){
			$al_products = exwoofood_get_option('exwoofood_ign_op','exwoofood_advanced_options');
			if($al_products!=''){
				$al_products = explode(",",$al_products);
				if(in_array($id_cr, $al_products)){
					$check_pr = true;
				}
			}
			$al_cats = exwoofood_get_option('exwoofood_igncat_op','exwoofood_advanced_options');
			if(is_array($al_cats) && !empty($al_cats)){
				if(has_term( $al_cats, 'product_cat', $id_cr ) ){
					$check_pr = true;
				}
			}
		}
		if ($enable_time == '' || $check_pr== true) {
			return true;
		}
		$cure_time =  exwfd_get_current_time();
		date_default_timezone_set('UTC');
		$hours_current= intval(date('H', $cure_time));
		$minutes_current = intval(date('i', $cure_time));
		// $times is time stamp start 00:00:00
		$times = $cure_time - $hours_current*3600 - $minutes_current*60;
		// Closed from date to date
		$closed_dates = exwoofood_get_option('exwfood_opcl_datetodate','exwoofood_advanced_options');
		if(is_array($closed_dates) && !empty($closed_dates)){
			foreach ($closed_dates as $key => $closed_date) {
				$cls_start = isset($closed_date['opcl_start']) ? $closed_date['opcl_start'] :'';
				$cls_end = isset($closed_date['opcl_end']) ? $closed_date['opcl_end'] :'';
				if($cls_start!='' && $cure_time >= $cls_start && $cls_end !='' && $cure_time <= $cls_end ){
					return false;
					break;
				}
			}
		}
		// advanced open closing time by day of week
		$opcl_time = exwoofood_get_option('exwfood_'.date('D',$cure_time).'_opcl_time','exwoofood_advanced_options');
		// for each location
		$log_selected = exwf_get_loc_selected();
		$loc_opcls = exwoofood_get_option('exwoofood_open_close_loc','exwoofood_advanced_options');
		if($log_selected!='' && $loc_opcls=='yes'){
			$closed_loc = get_term_meta( $log_selected, 'exwfood_loc_closed', true );
			if($closed_loc=='yes'){
				return false;
			}
			$opcl_time_log = get_term_meta( $log_selected, 'exwfood_'.date('D',$cure_time).'_opcl_time', true );
			$opcl_time = is_array($opcl_time_log) && !empty($opcl_time_log) ? $opcl_time_log : $opcl_time;
		}else if($log_selected=='' && $loc_opcls=='yes'){
			return true;
		}
		if(is_array($opcl_time) && !empty($opcl_time)){
			$check= true;
			foreach ($opcl_time as $it_time) {
				$open_hours = isset($it_time['open-time']) ? intval(date('H', strtotime($it_time['open-time'])))*3600 + intval(date('i', strtotime($it_time['open-time'])))*60 : 0 ;
				$close_hours = isset($it_time['close-time']) ? intval(date('H', strtotime($it_time['close-time'])))*3600 + intval(date('i', strtotime($it_time['close-time'])))*60 : 0 ;
				if($close_hours < $open_hours){
					$close_hours = $close_hours + 86400;
				}
				$open_hours_unix = $times + $open_hours;
				$close_hours_unix = $times + $close_hours;
				if ($open_hours_unix > $close_hours_unix || $cure_time < $open_hours_unix || $cure_time > $close_hours_unix) {
					$check= false;
				}else{
					$check= true;
					break;
				}
			}
			return $check;
		}else{
			$open_hours = exwoofood_get_option('exwoofood_ck_open_hour','exwoofood_advanced_options');
			$close_hours = exwoofood_get_option('exwoofood_ck_close_hour','exwoofood_advanced_options');
			if ($open_hours == '' || $close_hours == '') {
				return false;
			}
			$open_hours_unix = $times + intval(date('H', strtotime($open_hours)))*3600 + intval(date('i', strtotime($open_hours)))*60;
			$close_hours_unix = $times + intval(date('H', strtotime($close_hours)))*3600 + intval(date('i', strtotime($close_hours)))*60;
			// echo date_i18n(get_option('time_format'), $times).' '.date_i18n(get_option('time_format'), $open_hours_unix).' '.date_i18n(get_option('time_format'), $close_hours_unix);exit();
			if ($open_hours_unix > $close_hours_unix || $cure_time < $open_hours_unix || $cure_time > $close_hours_unix) {
				return false;
			}
			return true;
		}
		return $check_pr;
	}
}
/*-- Get next open hour--*/
if(!function_exists('exwfd_get_next_open_close_time')){
	function exwfd_get_next_open_close_time(){
		$cure_time =  exwfd_get_current_time();
		date_default_timezone_set('UTC');
		$hours_current= intval(date('H', $cure_time));
		$minutes_current = intval(date('i', $cure_time));
		// $times is time stamp start 00:00:00
		$times = $cure_time - $hours_current*3600 - $minutes_current*60;
		$open_hours = $close_hours = '';
		for ($i=0; $i < 7; $i++) {
			$check= false;
			$timck = $cure_time + ($i * 86400);
			$opcl_time = exwoofood_get_option('exwfood_'.date('D',$timck).'_opcl_time','exwoofood_advanced_options');
			// for each location
			$log_selected = exwf_get_loc_selected();
			if($log_selected!=''){
				$loc_opcls = exwoofood_get_option('exwoofood_open_close_loc','exwoofood_advanced_options');
				if($loc_opcls=='yes'){
					$opcl_time_log = get_term_meta( $log_selected, 'exwfood_'.date('D',$cure_time).'_opcl_time', true );
					$opcl_time = is_array($opcl_time_log) && !empty($opcl_time_log) ? $opcl_time_log : $opcl_time;
				}
			}
			if(is_array($opcl_time) && !empty($opcl_time)){
				
				foreach ($opcl_time as $it_time) {
					$open_hours = $it_time['open-time'];
					$close_hours = $it_time['close-time'];
					if($i == 0){
						$open_hours_unix = $times + intval(date('H', strtotime($open_hours)))*3600 + intval(date('i', strtotime($open_hours)))*60;
						$close_hours_unix = $times + intval(date('H', strtotime($close_hours)))*3600 + intval(date('i', strtotime($close_hours)))*60;
						if ($open_hours_unix >  $cure_time ) {
							$check= true;
							break;
						}
					}else if($open_hours!=$close_hours){

						$check= true;
						break;
					}
				}
			}
			if($check==true){
				break;
			}	
		}
		if($check==true){
			if($i ==0){ $timck = '';}
			return array($open_hours,$close_hours,$timck);
		}
	}
}
/*---- Open closing time message----*/
if(!function_exists('exwfd_open_closing_message')){
	function exwfd_open_closing_message($rhtml=false){
		$enable_time = exwoofood_get_option('exwoofood_open_close','exwoofood_advanced_options');
		ob_start();
		$next_op = exwfd_get_next_open_close_time();
		// Closed from date to date
		$closed_dates = exwoofood_get_option('exwfood_opcl_datetodate','exwoofood_advanced_options');
		$open_after = '';
		if(is_array($closed_dates) && !empty($closed_dates)){
			$cure_time =  exwfd_get_current_time();
			foreach ($closed_dates as $key => $closed_date) {
				$cls_start = isset($closed_date['opcl_start']) ? $closed_date['opcl_start'] :'';
				$cls_end = isset($closed_date['opcl_end']) ? $closed_date['opcl_end'] :'';
				if($cls_start!='' && $cure_time >= $cls_start && $cls_end !='' && $cure_time <= $cls_end ){
					$open_after = $cls_end;
					break;
				}
			}
		}
		$log_selected = exwf_get_loc_selected();
		$closed_loc = '';
		if($log_selected!=''){
			$loc_opcls = exwoofood_get_option('exwoofood_open_close_loc','exwoofood_advanced_options');
			if($loc_opcls=='yes'){
				$closed_loc = get_term_meta( $log_selected, 'exwfood_loc_closed', true );
			}
		}
		if($enable_time=='closed' || $closed_loc == 'yes'){
			$text = esc_html__( 'Ordering food is now closed','woocommerce-food');
		}else if($open_after!=''){
			$date_cls = date_i18n(get_option('date_format'),$open_after);
			$time_cls = date_i18n(get_option('time_format'),$open_after);
			$text = sprintf( esc_html__( 'Ordering food is now closed, please come back after %1$s %2$s', 'woocommerce-food' ), $date_cls, $time_cls);
		}else if(array($next_op) && !empty($next_op)){
			$fp = date_i18n(get_option('time_format'),strtotime($next_op[0]));
			$to = date_i18n(get_option('time_format'),strtotime($next_op[1]));
			$nday = isset($next_op[2]) && is_numeric($next_op[2]) ? date_i18n('l',$next_op[2]) : esc_html__( 'Today', 'woocommerce-food' );
			$text = sprintf( esc_html__( 'Ordering food is now closed, please come back from %1$s to %2$s %3$s', 'woocommerce-food' ), $fp, $to, $nday);
		}else{
			$text = esc_html__( 'Ordering food is now closed','woocommerce-food');
		}

		$text = apply_filters( 'exwfood_opcl_text', $text, $next_op );
		if(isset($rhtml) && $rhtml==true ){
			echo $text;
		}else{
			echo '<p class="exfd-out-notice excls-notice">' .$text.'</p>';
		}
		$html = ob_get_contents();
		ob_end_clean();
		return $html;
	}
}

if(!function_exists('exfd_show_reviews')){
	function exfd_show_reviews($id_food,$product=false){
		if(!isset($product) || $product==''){
	    	$product = wc_get_product( $id_food );
	    }
		if(function_exists('wc_get_rating_html')){
			$rating_html = wc_get_rating_html($product->get_average_rating());
		}else{
			$rating_html = $product->get_rating_html();
		}
		$rating_count = $product->get_rating_count();
		if (  $rating_count > 0 && get_option( 'woocommerce_enable_review_rating' ) != 'no' && $rating_html){
				return  '<div class="exwf-rating woocommerce">'.$rating_html.'</div>';
		}
    }
}


function exwf_custom_color($sc,$style,$id){
	$color = get_post_meta( get_the_ID(), 'exwoofood_custom_color',true );
	if($color==''){ return;}
	?>
	<style type="text/css">
		<?php if($sc=='grid'){
			if($style=='1' || $style=='2'){
				?>
				.ex-fdlist #<?php echo esc_attr($id);?> figcaption .exbt-inline > a,
				#<?php echo esc_attr($id);?> .exwoofood-woocommerce.woocommerce form.cart button[type="submit"]{background:<?php echo esc_attr($color);?>;}
				#<?php echo esc_attr($id);?> figcaption h5{color:<?php echo esc_attr($color);?>;}
				<?php
			}else if( $style=='3'){?>
				#<?php echo esc_attr($id);?> figcaption h5{color:<?php echo esc_attr($color);?>;}
				<?php
			}else if($style=='4'){?>
				.ex-fdlist #<?php echo esc_attr($id);?> .exfd-icon-plus:before,
				.ex-fdlist #<?php echo esc_attr($id);?> .exfd-icon-plus:after,
				#<?php echo esc_attr($id);?> figcaption h5{background:<?php echo esc_attr($color);?>;}
				.ex-fdlist #<?php echo esc_attr($id);?> .exstyle-4-button.exfd-choice{border-color:<?php echo esc_attr($color);?>;}
				<?php
			}
		}else if($sc=='list' || $sc=='table'){ ?>
			.ex-fdlist #<?php echo esc_attr($id);?> .exfd-icon-plus:before,
			.ex-fdlist #<?php echo esc_attr($id);?> .exfd-icon-plus:after,
			#<?php echo esc_attr($id);?> figcaption h5{background:<?php echo esc_attr($color);?>;}
			.ex-fdlist #<?php echo esc_attr($id);?> .exfd-choice{border-color:<?php echo esc_attr($color);?>;}
			<?php
		}?>
	</style>
	<?php
}
// search html
function exwf_search_html($enable_search){
	if($enable_search!='yes'){ return;}
	?>
	<div class="exwf-search">
		<form role="search" method="get" class="exwf-search-form" action="<?php echo home_url(); ?>/">
		
			<input type="hidden" name="post_type" value="product" />
	      	<input type="text" value="<?php the_search_query(); ?>" name="s" id="s" placeholder="<?php echo  esc_html__('Type Keywords','woocommerce-food'); ?>" class="exwf-s-field" />
	      	<button type="submit" class="exwf-s-submit" ><img src="<?php echo EX_WOOFOOD_PATH.'css/img/search-outline.svg';?>" alt="image-cart"></button>
		</form>
	</div>	
	<?php
}
add_filter( 'exwo_accordion_style', 'exwoofood_extra_option_accordion_style', 10, 1 );
function exwoofood_extra_option_accordion_style( $style ) {
	if ( exwoofood_get_option('exwoofood_exoptions_style') =='accordion' ) {
	   	$style = true;
	}
    return $style;
}
//Add info to pdf invoice
if(!function_exists('exwo_add_info_to_invoice')){
	add_action( 'wpo_wcpdf_after_order_data', 'exwo_add_info_to_invoice', 10, 3 );
	function exwo_add_info_to_invoice ( $type, $order) {
		$dv_date = $order->get_meta( 'exwfood_date_deli', true );//get_post_meta( $order->get_id(), 'exwfood_date_deli', true );
		$dv_time = $order->get_meta( 'exwfood_time_deli', true );//get_post_meta( $order->get_id(), 'exwfood_time_deli', true );
		$loc_ar = $order->get_meta( 'exwoofood_location', true );//get_post_meta( $order->get_id(), 'exwoofood_location', true );
		
		$text_datedel = exwf_date_time_text('date',$order);
		$text_timedel = exwf_date_time_text('time',$order);

		$order_method = $order->get_meta( 'exwfood_order_method', true );//get_post_meta( $order->get_id(), 'exwfood_order_method', true );
		$order_method = $order_method=='takeaway' ? esc_html__('Takeaway','woocommerce-food') : ( $order_method=='dinein' ? esc_html__('Dine-in','woocommerce-food') : ( $order_method=='delivery' ? esc_html__('Delivery','woocommerce-food') : '') );
    	if($order_method !=''){?>
    		<tr>
		    	<th><?php echo esc_html__('Order method','woocommerce-food'); ?></th>
		    	<td><?php echo $order_method; ?></td>
		    </tr>
		<?php }

		if($dv_date !=''){?>
		    <tr>
		    	<th><?php echo $text_datedel; ?></th>
		    	<td><?php echo $dv_date; ?></td>
		    </tr>
		<?php }
		if($dv_time !=''){
			?>
		    <tr>
		    	<th><?php echo $text_timedel; ?></th>
		    	<td><?php echo $dv_time; ?></td>
		    </tr>
		<?php }
		$log_name = get_term_by('slug', $loc_ar, 'exwoofood_loc');
		if($log_name->name){
			?>
		    <tr>
		    	<th><?php echo esc_html__( 'Location', 'woocommerce-food' ); ?></th>
		    	<td><?php echo $log_name->name; ?></td>
		    </tr>
		<?php }
	}
}
// auto print node

if(!function_exists('exwo_add_info_to_invoice_prnode')){
    add_action( 'woo_order_auto_print_before_order_data', 'exwo_add_info_to_invoice_prnode', 11, 4 );
	function exwo_add_info_to_invoice_prnode ( $order, $order_id, $template_id, $template_settings) {
		$dv_date = $order->get_meta( 'exwfood_date_deli', true );
		$dv_time = $order->get_meta( 'exwfood_time_deli', true );
		$loc_ar = $order->get_meta( 'exwoofood_location', true );
		$text_datedel = exwf_date_time_text('date',$order);
		$text_timedel = exwf_date_time_text('time',$order);
		$order_method = $order->get_meta( 'exwfood_order_method', true );//get_post_meta( $order->get_id(), 'exwfood_order_method', true );
		$order_method = $order_method=='takeaway' ? esc_html__('Takeaway','woocommerce-food') : ( $order_method=='dinein' ? esc_html__('Dine-in','woocommerce-food') : ( $order_method=='delivery' ? esc_html__('Delivery','woocommerce-food') : '') );
    	if($order_method !=''){
    		echo '<li class="order-date"><strong>'.esc_html__('Order method','woocommerce-food').'</strong>'. $order_method.'</li>';
		}
		if($dv_date !=''){
			echo '<li class="order-date"><strong>'.$text_datedel.'</strong>'. $dv_date.'</li>';
		}
		if($dv_time !=''){
			echo '<li class="order-date"><strong>'.$text_timedel.'</strong>'. $dv_time.'</li>';
		}
		$log_name = get_term_by('slug', $loc_ar, 'exwoofood_loc');
		if($log_name->name){
			echo '<li class="order-date"><strong>'.esc_html__( 'Location', 'woocommerce-food' ).'</strong>'. $log_name->name.'</li>';
		}
	}
}

if(!function_exists('exwo_add_info_to_invoice_pip')){
	//add_action( 'wc_pip_header', 'exwo_add_info_to_invoice_pip', 10, 4 );
	function exwo_add_info_to_invoice_pip ( $type, $action, $document, $order) {
		$dv_date = $order->get_meta( 'exwfood_date_deli', true );//get_post_meta( $order->get_id(), 'exwfood_date_deli', true );
		$dv_time = $order->get_meta( 'exwfood_time_deli', true );//get_post_meta( $order->get_id(), 'exwfood_time_deli', true );
		$loc_ar = $order->get_meta( 'exwoofood_location', true );//get_post_meta( $order->get_id(), 'exwoofood_location', true );
		$text_datedel = exwf_date_time_text('date',$order);
		$text_timedel = exwf_date_time_text('time',$order);
		$order_method = $order->get_meta( 'exwfood_order_method', true );//get_post_meta( $order->get_id(), 'exwfood_order_method', true );
		$order_method = $order_method=='takeaway' ? esc_html__('Takeaway','woocommerce-food') : ( $order_method=='dinein' ? esc_html__('Dine-in','woocommerce-food') : ( $order_method=='delivery' ? esc_html__('Delivery','woocommerce-food') : '') );
    	if($order_method !=''){?>
		    <h6 class="order-mt order-date"><?php echo esc_html__('Order method','woocommerce-food'); ?>: <?php echo $order_method; ?></h6>
		<?php }
		if($dv_date !=''){?>
		   <h6 class="order-del-date order-date"><?php echo $text_datedel; ?>: <?php echo $dv_date; ?></h6>
		<?php }
		if($dv_time !=''){
			?>
		    <h6 class="order-del-time order-date"><?php echo $text_timedel; ?>: <?php echo $dv_time; ?></h6>
		<?php }
		$log_name = get_term_by('slug', $loc_ar, 'exwoofood_loc');
		if($log_name->name){
			?>
			<h6 class="order-loc order-date"><?php echo esc_html__( 'Location', 'woocommerce-food' ); ?>: <?php echo $log_name->name; ?></h6>
		<?php }
	}
}
///
/*
function exwf_addoption_to_order_items( $item, $cart_item_key, $values, $order ) {

	//print_r($values);exit;
	if(isset($values['exoptions']) && !empty($values['exoptions'])){
		$title = get_the_title($values['product_id']);
		$option_name ='';
		foreach ($values['exoptions'] as $option) {
			$option_name .=  ' '.$option['name'].': '.$option['value'].'+'.wc_price($option['price']);
		}
		$title = $title.' -'.$option_name;
		$item->set_name($title);
	}

}
add_action( 'woocommerce_checkout_create_order_line_item', 'exwf_addoption_to_order_items', 10, 4 );
*/
function exwf_date_time_text($text,$order=false){
	$text_datedel = esc_html__('Delivery Date','woocommerce-food');
	$text_timedel = esc_html__('Delivery Time','woocommerce-food');
	if(isset($order) && is_object($order) && method_exists($order,'get_id')){
		$user_odmethod = $order->get_meta( 'exwfood_order_method', true );//get_post_meta( $order->get_id(), 'exwfood_order_method', true );
	}else{
		$user_odmethod = WC()->session->get( '_user_order_method' );
	}
	if($user_odmethod=='takeaway'){
		$text_datedel = esc_html__('Pickup Date','woocommerce-food');
		$text_timedel = esc_html__('Pickup Time','woocommerce-food');
	}
	if($user_odmethod=='dinein'){
		$text_datedel = esc_html__('Date','woocommerce-food');
		$text_timedel = esc_html__('Time','woocommerce-food');
	}
	if($text=='date'){
		return apply_filters('exwf_datedeli_text',$text_datedel);
	}else{
		return apply_filters('exwf_timedeli_text',$text_timedel);
	}
}
// change and using jquery to change text like above
//add_action('woocommerce_checkout_update_order_review', 'exwf_change_text_shipping_methods', 10, 1);
function exwf_change_text_shipping_methods( $post_data ) {
    parse_str($post_data, $get_array);
    $method = isset($get_array['shipping_method'][0]) ? $get_array['shipping_method'][0] : '';
    if($method=='flat_rate:3'){
    	WC()->session->set( '_user_order_method' , 'delivery');
    }else{
    	WC()->session->set( '_user_order_method' , 'takeaway');
    }
}

if(!function_exists('exwf_change_datelb_shipping_methods')){
	//add_filter('exwf_datedeli_text', 'exwf_change_datelb_shipping_methods', 10, 1);
	function exwf_change_datelb_shipping_methods( $text ) {
		if(is_admin()){
			global $pagenow;
			if (( $pagenow == 'post.php' ) || (get_post_type() == 'shop_order')) {
				$order = wc_get_order(get_the_ID());
				$method = @array_shift($order->get_shipping_methods());
				$method = isset($method['method_id']) ? $method['method_id'] : '';
			}
		}else{
			$method = WC()->session->get( 'chosen_shipping_methods' );
			$method = isset($method[0]) ? $method[0] : '';
		}
	    if (strpos($method, 'flat_rate') !== false) {
	    	$text = esc_html__('Delivery Date','woocommerce-food');
	    }else{
	    	$text = esc_html__('Pickup Date','woocommerce-food');
	    }
	    return $text;
	}
}

if(!function_exists('exwf_change_timelb_shipping_methods')){
	//add_filter('exwf_timedeli_text', 'exwf_change_timelb_shipping_methods', 10, 1);
	function exwf_change_timelb_shipping_methods( $text ) {
		if(is_admin()){
			global $pagenow;
			if (( $pagenow == 'post.php' ) || (get_post_type() == 'shop_order')) {
				$order = wc_get_order(get_the_ID());
				$method = @array_shift($order->get_shipping_methods());
				$method = isset($method['method_id']) ? $method['method_id'] : '';
			}
		}else{
			$method = WC()->session->get( 'chosen_shipping_methods' );
			$method = isset($method[0]) ? $method[0] : '';
		}
	    if (strpos($method, 'flat_rate') !== false) {
	    	$text = esc_html__('Delivery time','woocommerce-food');
	    }else{
	    	$text = esc_html__('Pickup time','woocommerce-food');
	    }
	    return $text;
	}
}

if(!function_exists('exwf_auto_update_label_script')){
	//add_action( 'wp_footer', 'exwf_auto_update_label_script', 999 );
	function exwf_auto_update_label_script() {
	    if (is_checkout()) :?>
	    <script>
	        jQuery( function( $ ) {
	            // woocommerce_params is required to continue, ensure the object exists
	            if ( typeof woocommerce_params === 'undefined' ) {
	                return false;
	            }
	            // Postkantoor shipping methods
	            //var show = ['flat_rate:3','flat_rate:7','flat_rate:8'];

	            $(document).on( 'change', '#shipping_method input[type="radio"]', function() {
	              // console.log($.inArray($(this).val(), show));
	              //if ($.inArray($(this).val(), show) > -1) {    // >-1 if found in array
	              	var $mth = $(this).val();
	              	var $rq = $rq_time = '';
					if($('#exwfood_date_deli_field').hasClass('validate-required')){
						$rq = '<abbr class="required" title="required">*</abbr>';
					}
					if($('#exwfood_time_deli_field').hasClass('validate-required')){
						$rq_time = '<abbr class="required" title="required">*</abbr>';
					}
					if($mth.indexOf("flat_rate") >= 0){
						$('#exwfood_date_deli_field label').html('<?php esc_html_e('Delivery Date','woocommerce-food') ?> '+$rq);
						$('#exwfood_time_deli_field label').html('<?php esc_html_e('Delivery Time','woocommerce-food') ?> '+$rq_time);
						//$('.billing-dynamic').removeClass('hide');
						// console.log('show');
					} else {
						$('#exwfood_date_deli_field label').html('<?php esc_html_e('Pickup Date','woocommerce-food') ?> '+$rq);
						$('#exwfood_time_deli_field label').html('<?php esc_html_e('Pickup Time','woocommerce-food') ?> '+$rq_time);
						//$('.billing-dynamic').addClass('hide');
						// console.log('hide');
					}
	            });

	        });
	    </script>
	    <?php
	    endif;
	}
}
function exwf_icon_color($id=false){
	if($id==false){
		$id = get_the_ID();
	}
	$icons = get_post_meta( $id, 'exwoofood_cticon_gr', true );
	if(is_array($icons) && !empty($icons)){
		echo '<span class="exwf-lbicons">';
		foreach ($icons as $icon) {
			$bg = isset($icon['bgcolor']) && $icon['bgcolor']!='' ? 'background-color:'.$icon['bgcolor'] : '';
			$lb = isset($icon['lb_name']) ? $icon['lb_name'] : '';
			$img = isset($icon['icon']) && $icon['icon']!='' ? 'background-image:url('.esc_url($icon['icon']).')' : '';
			?>
			<span>
				<span class="exwf-lbicon <?php echo $img=='' ? 'exwf-ep-ic' : '';?>" style="<?php echo $bg.';'.$img;?>"></span>
				<?php echo $lb!='' ? '<span class="exwf-lbname">'.$lb.'</span>' : '' ?>
			</span>
			<?php
		}
		echo '</span>';
	}
}
add_action( 'woocommerce_product_thumbnails', 'exwf_icon_color',12 ); 
/*
* Check if products from cart are not disable shiping feature
* Return true if one or all products is not disable shiping feature of Food
* Return false if all products are disable
*/
function exwf_if_check_product_notin_shipping(){
	$al_products = exwoofood_get_option('exwoofood_ign_deli','exwoofood_advanced_options');
	$al_cats = exwoofood_get_option('exwoofood_igncat_deli','exwoofood_advanced_options');
	$check_ex = true;
	if($al_products!='' || (is_array($al_cats) && !empty($al_cats))){
		$check_ex = false;
		$al_products = $al_products!='' ? explode(",",$al_products) : array();
		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
			$id_cr = $cart_item['product_id'];
			if((get_post_type($id_cr) != 'product_variation' && get_post_type($id_cr) != 'product') ){
			}else 
			if(is_array($al_cats) && !empty($al_cats)){
				if(!in_array($id_cr, $al_products) && !has_term( $al_cats, 'product_cat', $id_cr ) ){
					$check_ex = true;
					break;
				}
			}else{
				if(!empty($al_products) && !in_array($id_cr, $al_products)){
					$check_ex = true;
					break;
				}
			}
		}
	}
	return $check_ex;
}
/*
* Check if products from cart are disable shiping feature
* Return true if one or all products is disable shiping feature of food
* Return false if all products are not disable
*/
function exwf_if_check_product_in_shipping(){
	$al_products = exwoofood_get_option('exwoofood_ign_deli','exwoofood_advanced_options');
	$al_cats = exwoofood_get_option('exwoofood_igncat_deli','exwoofood_advanced_options');
	$check_ex = true;
	if($al_products!='' || (is_array($al_cats) && !empty($al_cats)) ){
		$check_ex = false;
		$al_products = $al_products!='' ? explode(",",$al_products) : array();
		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
			$id_cr = $cart_item['product_id'];
			if((get_post_type($id_cr) != 'product_variation' && get_post_type($id_cr) != 'product') ){
				$check_ex = true;
				break;
			}else 
			if(is_array($al_cats) && !empty($al_cats)){
				if(in_array($id_cr, $al_products) || has_term( $al_cats, 'product_cat', $id_cr ) ){
					$check_ex = true;
					break;
				}
			}else{
				if( !empty($al_products) &&  in_array($id_cr, $al_products)){
					$check_ex = true;
					break;
				}
			}
		}
	}else{
		$check_ex = false;
	}
	return $check_ex;
}
/*
* Open single product on popup
*/
add_action( 'template_redirect', 'exwfredirect_single_product' );
function exwfredirect_single_product() {
	$menu_url = exwoofood_get_option('exwoofood_menu_url','exwoofood_options');
	if ($menu_url !=''&& is_singular( 'product' ) &&  filter_var($menu_url, FILTER_VALIDATE_URL) !== FALSE ) {
		$postid = get_queried_object_id();
		$menu_url = add_query_arg( 'wfproduct_id', $postid, $menu_url );
		$menu_url = apply_filters('exwf_single_url_popup',$menu_url,$postid);
		wp_redirect( $menu_url);
		exit;
	}
}
add_action( 'exwoofood_before_shortcode', 'exwf_add_hidden_product_from_link' );
function exwf_add_hidden_product_from_link() {
	if (isset($_GET['wfproduct_id']) && is_numeric($_GET['wfproduct_id'])) {
		global $modal_html; if($modal_html=="on"){ return;}
		remove_action( 'exwoofood_before_shortcode', 'exwf_add_hidden_product_from_link' );
		$id_el = 'exwf-single-'.$_GET['wfproduct_id'];
		echo '<div class="ex-hidden" id="'.esc_attr($id_el).'">'.do_shortcode('[ex_wf_ordbutton product_id="'.$_GET['wfproduct_id'].'"]').'
			<script>
			jQuery(document).ready(function($) {
				var contenId = "#'.esc_attr($id_el).' .item-grid[data-id_food='.$_GET['wfproduct_id'].'] a";
				if($(contenId).length){
					$(contenId).first().trigger("click");
					return;
				}
			});
			</script>
		</div>';
	}
}
/*
* mobile toolbar
*/
add_action( 'exwf_after_shortcode_content', 'exwf_add_mobile_bar' );
function exwf_add_mobile_bar($atts) {
	$hide_atc =  isset($atts['hide_atc']) ? $atts['hide_atc'] :'';
	if($hide_atc=='yes'){
		return;
	}else{
		$enable_mbnav = isset($atts['enable_mbnav']) ? $atts['enable_mbnav'] : '';
		if($enable_mbnav!='no'){
			exwoofood_template_plugin('mobile-nav-bar',1);
		}
	}
}
// convent price
function exwf_price_wmc($number){
	$uc_number = $number;
	//if($number=='' || !is_numeric($number)){ return;}
	if($number==''){ return;}
	if(get_option( 'woocommerce_price_decimal_sep' )==','){
		$number = floatval(str_replace(',', '.', $number));
	}else if(get_option( 'woocommerce_price_decimal_sep' )=='.' && strpos($number, ',') !== false){
		$number = floatval(str_replace(',', '.', str_replace('.', '', $number)));
	}
	if(!is_numeric($number)){ return;}
	if(isset($cv) && $cv==true){
		$number = exwo_price_display($number);
	}
	if(function_exists('wmc_get_price')){
		$number =  wmc_get_price($number);
	}
	return apply_filters('exwf_price_wmc',$number,$uc_number);
}
// date field
function exwf_date_selecter_pu($user_date,$text_datedel){
    $date_before = exwoofood_get_option('exwoofood_ck_beforedate','exwoofood_advanced_options');
    $enb_date = exwoofood_get_option('exwoofood_ck_enadate','exwoofood_advanced_options');
    $dis_date = exwoofood_get_option('exwoofood_ck_disdate','exwoofood_advanced_options');
    $dis_day = exwoofood_get_option('exwoofood_ck_disday','exwoofood_advanced_options');
    $cure_time =  strtotime("now");
    $gmt_offset = exwf_df_gmt_offset();
    if($date_before!='' && is_numeric($date_before)){
        $cure_time =  apply_filters( 'exwt_disable_book_day', strtotime("+$date_before day") );
    }else if($date_before!='' && is_numeric(str_replace("m","",$date_before))){
        $cure_time = apply_filters( 'exwt_disable_book_day', strtotime("+".str_replace("m","",$date_before)." minutes") );
    }
    if($gmt_offset!=''){$cure_time = $cure_time + ($gmt_offset*3600);}
    $date = strtotime(date('Y-m-d', $cure_time));
    $maxl = apply_filters('exwf_number_date_select',10);
    $deli_date = array();
    $html = $html_ot = '';
    $dspl_type = exwoofood_get_option('exwoofood_dd_display','exwoofood_advanced_options');
    if($dspl_type!='picker'){
        $_fmdate = apply_filters('exwf_food_by_date_fm', get_option('date_format'));
        if(is_array($enb_date) && count($enb_date) > 0){
            $html_ot .= '<option selected="true" value="" disabled>'.esc_html__('-- Select --','woocommerce-food') .'</option>';
            $avdate = false;
            foreach ($enb_date as $enb_date_it) {
                if($enb_date_it > $date){
                	$avdate = true;
                    $date_fm = date_i18n($_fmdate, $enb_date_it);
                    $deli_date[$enb_date_it] = $date_fm;
                    $html_ot .= '<option value="'. $enb_date_it .'" data-date="'.esc_attr(date('Y-m-d',$enb_date_it)).'">'. $date_fm .'</option>';
                }
            }
            if($avdate == false){
            	$html_ot = '<option selected="true" value="" disabled>'.esc_html__('No date available for selection','woocommerce-food') .'</option>';
            }
        }else{
            $html_ot .= '<option selected="true" value="" disabled>'.esc_html__('-- Select --','woocommerce-food') .'</option>';
            $avdate = false;
            for ($i = 0 ; $i<= $maxl; $i ++ ) {
                $date_un = strtotime("+$i day", $date);
                $day_ofdate = date('N',$date_un);
                if((!empty($dis_day) && count($dis_day)==7)){ break;}
                if( (!empty($dis_date) && in_array($date_un, $dis_date )) || (!empty($dis_day) && in_array($day_ofdate, $dis_day ) ) ){
                  $maxl = $maxl +1;
                }else{
                	$avdate = true;
					$date_fm = date_i18n($_fmdate, $date_un);
					$deli_date[$date_un] = $date_fm;
					$html_ot .= '<option value="'. $date_un .'" data-date="'.esc_attr(date('Y-m-d',$date_un)).'">'. $date_fm .'</option>';
                }
            }
            if($avdate == false){
            	$html_ot = '<option selected="true" value="" disabled>'.esc_html__('No date available for selection','woocommerce-food') .'</option>';
            }
        }
        $mntimesl = exwoofood_get_option('exwoofood_foodby_timesl');
        $css_cls = '';
        if($mntimesl=='yes'){ $css_cls = 'exwf-mn-timesl exwf-disable-red';}
        $html ='<select id="exwfood_date_deli" class="exwfood_date_deli '.esc_attr($css_cls).'" name="exwfood_date_deli">'.$html_ot.'</select>';
    }else if($dspl_type=='picker'){
        $date_fm = exwoofood_get_option('exwoofood_datepk_fm','exwoofood_advanced_options');
        $ct_attr = array();
        if($date_fm=='dd-mm-yyyy'){$php_fm = 'd-m-Y';}else{$php_fm = 'm/d/Y';}
        $disable_book = '0';
        $dis_uni = '0';
        if($date_before!='' && is_numeric($date_before)){
            $dis_uni = apply_filters( 'exwt_disable_book_day', strtotime("+$date_before day") );
        }else if($date_before!='' && is_numeric(str_replace("m","",$date_before))){
            $dis_uni = apply_filters( 'exwt_disable_book_day', strtotime("+".str_replace("m","",$date_before)." minutes") );
        }
        if($dis_uni!=''){
            if($gmt_offset!=''){
                $dis_uni = $dis_uni + ($gmt_offset*3600);
            }
            $disable_book = date_i18n('Y-m-d',$dis_uni);
        }
        $ct_attr['data-disday'] = $ct_attr['data-disdate'] = $ct_attr['data-fm'] ='';
        if(is_array($dis_day) && count($dis_day)>0){
            $dis_day_st = implode(',',$dis_day);
            $ct_attr['data-disday'] = str_replace('7', '0', $dis_day_st);
            foreach ( $dis_day as $dditem ) {
                if(date_i18n('w',$dis_uni) == $dditem){
                    $dis_uni = $dis_uni + 86400;
                }
            }
            $disable_book = date_i18n('Y-m-d',$dis_uni);
        }
        $ct_attr['data-mindate'] = $disable_book;
        $tsl_fmonth = array(esc_html__('January','woocommerce-food'),esc_html__('February','woocommerce-food'),esc_html__('March','woocommerce-food'),esc_html__('April','woocommerce-food'),esc_html__('May','woocommerce-food'),esc_html__('June','woocommerce-food'),esc_html__('July','woocommerce-food'),esc_html__('August','woocommerce-food'),esc_html__('September','woocommerce-food'),esc_html__('October','woocommerce-food'),esc_html__('November','woocommerce-food'),esc_html__('December','woocommerce-food'));
        $ct_attr['data-fmon'] = str_replace('\/', '/', json_encode($tsl_fmonth));
        $tsl_smonth = array(esc_html__('Jan','woocommerce-food'),esc_html__('Feb','woocommerce-food'),esc_html__('Mar','woocommerce-food'),esc_html__('Apr','woocommerce-food'),esc_html__('May','woocommerce-food'),esc_html__('Jun','woocommerce-food'),esc_html__('Jul','woocommerce-food'),esc_html__('Aug','woocommerce-food'),esc_html__('Sep','woocommerce-food'),esc_html__('Oct','woocommerce-food'),esc_html__('Nov','woocommerce-food'),esc_html__('December','woocommerce-food'));
        $ct_attr['data-smon'] = str_replace('\/', '/', json_encode($tsl_smonth));
        $tsl_sday = array(esc_html__('Su','woocommerce-food'),esc_html__('Mo','woocommerce-food'),esc_html__('Tu','woocommerce-food'),esc_html__('We','woocommerce-food'),esc_html__('Th','woocommerce-food'),esc_html__('Fr','woocommerce-food'),esc_html__('Sa','woocommerce-food'));
        $ct_attr['data-sday'] = str_replace('\/', '/', json_encode($tsl_sday));
        $ct_attr['data-fiday'] = apply_filters( 'exwt_datepk_fday', 1);
        $arr_disdate=array();
        if(is_array($dis_date) && count($dis_date)>0){
            foreach ( $dis_date as $item ) {
                if(date_i18n('Y-m-d',$dis_uni) == date_i18n('Y-m-d',$item)){
                    $dis_uni = $dis_uni + 86400;
                }
                $arr_disdate[] = date($php_fm, $item);
            }
            $ct_attr['data-mindate'] = date_i18n('Y-m-d',$dis_uni);
            $arr_disdate = str_replace('\/', '/', json_encode($arr_disdate));
        }
        wp_enqueue_style( 'exwf-date', EX_WOOFOOD_PATH . 'js/jquery-timepicker/bootstrap-datepicker.css');
        wp_enqueue_script( 'exwf-date-js', EX_WOOFOOD_PATH . 'js/jquery-timepicker/bootstrap-datepicker.js', array( 'jquery' ) );
        $html .= '<input type="text" class="input-text " name="exwfood_date_deli" id="exwfood_date_deli" placeholder="" value="'.esc_attr($user_date!='' ? date($php_fm, strtotime($user_date)) : '').'" data-date="'.esc_attr($user_date).'" data-fm="'.esc_attr($date_fm).'" data-disdate="'.esc_attr($arr_disdate).'" data-disday="'.esc_attr($ct_attr['data-disday']).'" data-mindate="'.esc_attr($ct_attr['data-mindate']).'" data-fmon="'.esc_attr($ct_attr['data-fmon']).'" data-smon="'.esc_attr($ct_attr['data-smon']).'" data-sday="'.esc_attr($ct_attr['data-sday']).'" data-fiday="'.esc_attr($ct_attr['data-fiday']).'" readonly="readonly">';
    }
    $html = '<div id="exwfood_date_deli_field">
        <span>'.$text_datedel.'</span>
        <div class="">'.$html.'</div>
        <p class="exwf-add-error">'.esc_html__('Please choose a date','woocommerce-food').'</p>
    </div>';
    return $html;
}
// date field
function exwf_get_current_date(){
	$cure_time =  strtotime("now");
	$gmt_offset = exwf_df_gmt_offset();
	if($gmt_offset!=''){
		$date = strtotime(date("Y-m-d",($cure_time + ($gmt_offset*3600)) ));
	}else{
		$date = strtotime(date("Y-m-d",$cure_time));
	}
	return $date;
}
function exwf_time_selecter_pu($rq_time,$rq_date,$user_time){
	ob_start();
	$text_timedel = exwf_date_time_text('time');
	$date_before = exwoofood_get_option('exwoofood_ck_beforedate','exwoofood_advanced_options');
    $cure_time =  strtotime("now");
    $gmt_offset = exwf_df_gmt_offset();
    $array_time = $deli_time = array();
    $array_time = exwoofood_get_option('exwoofood_ck_times','exwoofood_advanced_options');
    $adv_timesl = exwoofood_get_option('exwfood_adv_timedeli','exwoofood_adv_timesl_options');
    $_ftimesl = '';
    $method = WC()->session->get( '_user_order_method' );
    $method = $method !='' ? $method : 'delivery';
    if($rq_date=='disable'){
        $date_deli = exwf_get_current_date();
    }else{ $date_deli ='';}
    if( $date_deli !='' && is_array($adv_timesl) && !empty($adv_timesl)){
        $day_ofd = date('D',$date_deli);
        $user_log = WC()->session->get( '_user_deli_log' );
        foreach ($adv_timesl as $it_timesl) {
            $tsl_log = isset($it_timesl['times_loc'])  ?  $it_timesl['times_loc'] :'';
            if( isset ($it_timesl['repeat_'.$day_ofd]) && $it_timesl['repeat_'.$day_ofd] =='on' && 
                (!isset($it_timesl['deli_method']) 
                    || (isset($it_timesl['deli_method']) && $it_timesl['deli_method']=='') 
                    || (isset($it_timesl['deli_method']) && $it_timesl['deli_method']==$method)
                ) && ($tsl_log=='' || is_array($tsl_log) && in_array($user_log, $tsl_log)) ){
                $_ftimesl = isset($it_timesl['exwfood_deli_time']) && is_array($it_timesl['exwfood_deli_time']) ? $it_timesl['exwfood_deli_time'] : '';
                break;
            }
        }
    }
    $n_dl_time = $_ftimesl!= '' ?  $_ftimesl : exwoofood_get_option('exwfood_deli_time','exwoofood_advanced_options');
    $disable_sl = exwoofood_get_option('exwoofood_disable_tslot','exwoofood_advanced_options');
    if($disable_sl=='yes' && is_array($n_dl_time)){
        foreach ($n_dl_time as $key => $it_dl_time) {
            if(isset($it_dl_time['disable-slot']) && $it_dl_time['disable-slot']=='1' ){
                unset($n_dl_time[$key]);
            }
        }
    }
    if(!empty($n_dl_time)){
        $array_time = $n_dl_time;
    }
    if (empty($array_time)) {?>
            
        <span><?php echo $text_timedel;?></span>
        <div class="woocommerce-input-wrapper">
            <input type="text" name="exwfood_time_deli" id="exwfood_time_deli" placeholder="<?php  esc_html__( 'Select a time slot','woocommerce-food' );?>" value="<?php echo $user_time!='' ? esc_attr($user_time) : ''; ?>">
        </div>
        <p class="exwf-add-error"><?php esc_html_e('Please choose a time slot','woocommerce-food');?></p>
        <?php 
    }else{
        if($rq_time=='no'){
            $deli_time[] = '';
        }
        $exwf_disslot = apply_filters('exwf_hide_slot_unavailable','yes');
        $time_attr = array();
        $time_attr['data-time'] = json_encode($n_dl_time);
        $cure_time =  strtotime("now");
        if($gmt_offset!=''){
            $cure_time = $cure_time + ($gmt_offset*3600);
        }
        if(is_numeric($date_before)){
            $cure_time =  apply_filters( 'exwt_disable_book_day', strtotime("+$date_before day") );
        }else if($date_before!='' && is_numeric(str_replace("m","",$date_before))){
            $cure_time = $cure_time + str_replace("m","",$date_before)*60;
        }
        $time_attr['data-crtime'] = $cure_time;
        $time_attr['data-date'] = strtotime(date('Y-m-d', $cure_time));
        if(!empty($n_dl_time)){
            foreach ($array_time as $time_option) {
                $r_time ='';
                if(isset($time_option['start-time']) && $time_option['start-time']!='' && isset($time_option['end-time']) && $time_option['end-time']!=''){
                    $r_time = $time_option['start-time'].' - '.$time_option['end-time'];
                }elseif(isset($time_option['start-time']) && $time_option['start-time']!=''){
                    $r_time = $time_option['start-time'];
                }
                $name = isset($time_option['name-ts']) && $time_option['name-ts']!=''? $time_option['name-ts'] : $r_time;

                $disable ='';
                $st_sl = isset($time_option['start-time']) ? isset($time_option['start-time']) :'';
                $_time_base = apply_filters('exwf_timebase_to_check_delivery',$st_sl,$time_option);
                if($_time_base!=''){
                    $_timeck = $_time_base;
                    $_timeck = explode(':', $_timeck);
                    $_timeck = isset($_timeck[1]) ? $_timeck[1] * 60 + $_timeck[0] * 3600 : 0;
                    if((exwf_get_current_date() + $_timeck) < $cure_time){
                        $disable ='disabled="disabled"';
                    }
                }
                if($exwf_disslot=='yes' && $disable =='disabled="disabled"' ){
                }else{
                    $deli_time[$name] = $name;
                }
            }
            if(empty($deli_time)){$deli_time[''] = esc_html__('No time slot available for selection','woocommerce-food');}
        }else{
            foreach ($array_time as $time_option) {
                $deli_time[$time_option] = $time_option;
            }
        }
        
        woocommerce_form_field( 
            'exwfood_time_deli', array(
                'type'          => 'select',
                'required'  =>  false,
                'class'         => array('exwfood-time-deli form-row-wide'),
                'label'         => $text_timedel,
                'placeholder'   => '',
                'options' => $deli_time,
                'default' => '',
                'custom_attributes' => $time_attr, 
            ),
            $user_time
        );
    }
    $html = ob_get_contents();
	ob_end_clean();
	return $html;
}
/*
add_filter( 'exwf_get_number_orders_timeslot', 'exwf_get_number_order_bysql',12,6 );
function exwf_get_number_order_bysql($date,$time,$loc,$method,$tsl_method,$timeslots) {
	$get_orders = array();
	$get_orders['sql'] = 'yes';
	global $wpdb;
	$count =  $wpdb->get_row($wpdb->prepare("
		SELECT COUNT(*) AS THE_COUNT 
		FROM $wpdb->postmeta, $wpdb->postmeta AS mt1, $wpdb->postmeta AS mt2
		WHERE $wpdb->postmeta.meta_key = 'exwfood_time_deli' 
		AND $wpdb->postmeta.meta_value = %s
		AND mt1.meta_key = 'exwfood_date_deli_unix' 
		AND mt1.meta_value = %d
		AND mt2.meta_key = 'exwfood_order_method' 
		AND mt2.meta_value = %s",
		$time,
		$date,
		$method
		)
	);


	$enable_adv_tl = exwoofood_get_option('exwoofood_adv_loca','exwoofood_advanced_options');
	if($enable_adv_tl=='enable' && $loc!=''){
		$get_orders['total'] = $wpdb->get_row("SELECT COUNT(*) AS THE_COUNT FROM $wpdb->postmeta WHERE (meta_key = 'exwfood_time_deli' AND meta_value = '".$time."') AND (meta_key = 'exwfood_date_deli_unix' AND meta_value = '".$date."') AND (meta_key = 'exwfood_order_method' AND meta_value = '".$method."') AND (meta_key = 'exwoofood_location' AND meta_value = '".$loc."')");
	}
	$get_orders['total'] = $count->THE_COUNT;
	return $get_orders;
}*/

/*
add_filter( 'exwf_get_number_orders_timeslot', 'exwf_get_number_order_bysql',12,6 );
function exwf_get_number_order_bysql($date,$time,$loc,$method,$tsl_method,$timeslots) {
	$get_orders = array();
	$get_orders['sql'] = 'yes';//return $get_orders;
	global $wpdb;
	$querystr = "
	    SELECT $wpdb->posts.* 
	    FROM $wpdb->posts, $wpdb->postmeta, $wpdb->postmeta AS mt1
	    WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id 
		AND $wpdb->posts.ID = mt1.post_id
		
	    AND $wpdb->postmeta.meta_key = 'exwfood_date_deli_unix' 
	    AND $wpdb->postmeta.meta_value = '$date' 
	    AND mt1.meta_key = 'exwfood_time_deli' 
	    AND mt1.meta_value = '$time' 
		AND $wpdb->posts.post_type = 'shop_order'
	    ORDER BY $wpdb->posts.post_date DESC
	";
	$results = $wpdb->get_results($querystr, OBJECT);
	$get_orders['total'] = count($results);
	return $get_orders;
}
*/
/*--Timezone by loc--*/
function exwf_df_gmt_offset(){
	$gmt_offset = get_option('gmt_offset');
	return apply_filters('exwf_df_gmt_offset',$gmt_offset);
}
add_filter('exwf_df_gmt_offset','exwf_change_gmt_offset');
function exwf_change_gmt_offset( $val ){
	if(is_admin()&& !defined( 'DOING_AJAX' ) || !isset(WC()->session) ){ return $val;}
	$loc_selected = exwf_get_loc_selected();
	if($loc_selected!=''){
		$loc_timezone = get_term_meta( $loc_selected, 'exwp_loc_timezone', true );
		if($loc_timezone!=''){
			return $loc_timezone;
		}
	}
	return $val;
};

add_action('exwoofood_before_shortcode','exwf_cpt_mixmax');
function exwf_cpt_mixmax( $val ){
	if(function_exists('wc_mnm_init')){
		wp_enqueue_script( 'wc-add-to-cart-mnm' );
	}
};

if(!function_exists('exwf_social_share')){
	add_action('exwf_modal_after_content','exwf_social_share');
	function exwf_social_share( $id ){
		if(exwoofood_get_option('exwf_disable_social')!='yes'){
			return;
		}
		$id = $id =='' ? $id : get_the_ID();
		$exwf_share_button = array('fb','tw','li','tb','wa','pin','vk','em');
		$disable_sc = exwoofood_get_option('exwf_dispc_social');
		if(is_array($disable_sc) && !empty($disable_sc) ){
			$exwf_share_button = array_diff($exwf_share_button,$disable_sc);
		}
		if(is_array($exwf_share_button) && !empty($exwf_share_button)){
			?>
			<div class="exwf-social-share">
				<?php if(in_array('fb', $exwf_share_button)){ ?>
					<span class="facebook">
						<a class="trasition-all" title="<?php esc_html_e('Share on Facebook','woocommerce-food');?>" href="#" target="_blank" rel="nofollow" onclick="window.open('https://www.facebook.com/sharer/sharer.php?u='+'<?php echo urlencode(get_permalink($id)); ?>','facebook-share-dialog','width=626,height=436');return false;"><i class="ion-social-facebook-outline"></i>
						</a>
					</span>
				<?php }
				if(in_array('tw', $exwf_share_button)){ ?>
					<span class="twitter">
						<a class="trasition-all" href="#" title="<?php esc_html_e('Share on Twitter','woocommerce-food');?>" rel="nofollow" target="_blank" onclick="window.open('http://twitter.com/share?text=<?php echo urlencode(html_entity_decode(get_the_title($id), ENT_COMPAT, 'UTF-8')); ?>&amp;url=<?php echo urlencode(get_permalink($id)); ?>','twitter-share-dialog','width=626,height=436');return false;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="13" height="13">
							<path d="M389.2 48h70.6L305.6 224.2 487 464H345L233.7 318.6 106.5 464H35.8L200.7 275.5 26.8 48H172.4L272.9 180.9 389.2 48zM364.4 421.8h39.1L151.1 88h-42L364.4 421.8z"/>
							</svg>
						</a>
					</span>
				<?php }
				if(in_array('wa', $exwf_share_button)){ ?>
					<span class="WhatsApp">
						<a class="trasition-all" href="#" title="<?php esc_html_e('Share on WhatsApp','woocommerce-food');?>" rel="nofollow" target="_blank" onclick="window.open('https://api.whatsapp.com/send?text=<?php echo urlencode(html_entity_decode(get_the_title($id), ENT_COMPAT, 'UTF-8')); ?> - <?php echo urlencode(get_permalink($id)); ?>');return false;"><i class="ion-social-whatsapp-outline"></i>
						</a>
					</span>
				<?php }
				if(in_array('li', $exwf_share_button)){ ?>
						<span class="linkedin">
							<a class="trasition-all" href="#" title="<?php esc_html_e('Share on LinkedIn','woocommerce-food');?>" rel="nofollow" target="_blank" onclick="window.open('http://www.linkedin.com/shareArticle?mini=true&amp;url=<?php echo urlencode(get_permalink($id)); ?>&amp;title=<?php echo urlencode(html_entity_decode(get_the_title($id), ENT_COMPAT, 'UTF-8')); ?>&amp;source=<?php echo urlencode(get_bloginfo('name')); ?>','linkedin-share-dialog','width=626,height=436');return false;"><i class="ion-social-linkedin-outline"></i>
							</a>
						</span>
				<?php }
				if(in_array('tb', $exwf_share_button)){ ?>
					<span class="tumblr">
					   <a class="trasition-all" href="#" title="<?php esc_html_e('Share on Tumblr','woocommerce-food');?>" rel="nofollow" target="_blank" onclick="window.open('http://www.tumblr.com/share/link?url=<?php echo urlencode(get_permalink($id)); ?>&amp;name=<?php echo urlencode(html_entity_decode(get_the_title($id), ENT_COMPAT, 'UTF-8')); ?>','tumblr-share-dialog','width=626,height=436');return false;"><i class="ion-social-tumblr-outline"></i>
					   </a>
					</span>
				<?php }
				 if(in_array('pin', $exwf_share_button)){ ?>
					 <span class="pinterest">
						<a class="trasition-all" href="#" title="<?php esc_html_e('Pin this','woocommerce-food');?>" rel="nofollow" target="_blank" onclick="window.open('//pinterest.com/pin/create/button/?url=<?php echo urlencode(get_permalink($id)) ?>&amp;media=<?php echo urlencode(wp_get_attachment_url( get_post_thumbnail_id($id))); ?>&amp;description=<?php echo urlencode(html_entity_decode(get_the_title($id), ENT_COMPAT, 'UTF-8')); ?>','pin-share-dialog','width=626,height=436');return false;"><i class="ion-social-pinterest-outline"></i>
						</a>
					 </span>
				 <?php }
				 if(in_array('em', $exwf_share_button)){ ?>
					<span class="email">
						<a class="trasition-all" href="mailto:?subject=<?php echo urlencode(html_entity_decode(get_the_title($id), ENT_COMPAT, 'UTF-8')); ?>&amp;body=<?php echo urlencode(get_permalink($id)) ?>" title="<?php esc_html_e('Email this','woocommerce-food');?>"><i class="ion-ios-email-outline"></i>
						</a>
					</span>
				<?php }?>
			</div>
			<?php
		}
	}
}