if(!$q->get('czk_vendor_search')||!$sql) return $sql;
  global $wpdb;
  $like='%'.$wpdb->esc_like($q->get('s')).'%';
  $extra=$wpdb->prepare("EXISTS (SELECT 1 FROM {$wpdb->usermeta} czkv WHERE czkv.user_id={$wpdb->posts}.post_author AND czkv.meta_key='dokan_store_name' AND czkv.meta_value LIKE %s) OR EXISTS (SELECT 1 FROM {$wpdb->postmeta} czks WHERE czks.post_id={$wpdb->posts}.ID AND czks.meta_key='_sku' AND czks.meta_value LIKE %s)",$like,$like);
  return ' AND (('.preg_replace('/^\s*AND\s+/i','',trim($sql)).') OR '.$extra.')';
 }
 private static function flags($slug) { $flags=['antigua-and-barbuda'=>'🇦🇬','australia'=>'🇦🇺','bahamas'=>'🇧🇸','the-bahamas'=>'🇧🇸','bangladesh'=>'🇧🇩','barbados'=>'🇧🇧','belize'=>'🇧🇿','botswana'=>'🇧🇼','brunei'=>'🇧🇳','brunei-darussalam'=>'🇧🇳','cameroon'=>'🇨🇲','canada'=>'🇨🇦','cyprus'=>'🇨🇾','dominica'=>'🇩🇲','eswatini'=>'🇸🇿','fiji'=>'🇫🇯','gabon'=>'🇬🇦','gambia'=>'🇬🇲','the-gambia'=>'🇬🇲','ghana'=>'🇬🇭','grenada'=>'🇬🇩','guyana'=>'🇬🇾','india'=>'🇮🇳','jamaica'=>'🇯🇲','kenya'=>'🇰🇪','kiribati'=>'🇰🇮','lesotho'=>'🇱🇸','malawi'=>'🇲🇼','malaysia'=>'🇲🇾','maldives'=>'🇲🇻','malta'=>'🇲🇹','mauritius'=>'🇲🇺','mozambique'=>'🇲🇿','namibia'=>'🇳🇦','nauru'=>'🇳🇷','new-zealand'=>'🇳🇿','nigeria'=>'🇳🇬','pakistan'=>'🇵🇰','papua-new-guinea'=>'🇵🇬','rwanda'=>'🇷🇼','saint-kitts-and-nevis'=>'🇰🇳','st-kitts-and-nevis'=>'🇰🇳','saint-lucia'=>'🇱🇨','st-lucia'=>'🇱🇨','saint-vincent-and-the-grenadines'=>'🇻🇨','st-vincent-and-the-grenadines'=>'🇻🇨','samoa'=>'🇼🇸','seychelles'=>'🇸🇨','sierra-leone'=>'🇸🇱','singapore'=>'🇸🇬','solomon-islands'=>'🇸🇧','south-africa'=>'🇿🇦','sri-lanka'=>'🇱🇰','tanzania'=>'🇹🇿','united-republic-of-tanzania'=>'🇹🇿','togo'=>'🇹🇬','tonga'=>'🇹🇴','trinidad-and-tobago'=>'🇹🇹','tuvalu'=>'🇹🇻','uganda'=>'🇺🇬','united-kingdom'=>'🇬🇧','uk'=>'🇬🇧','vanuatu'=>'🇻🇺','zambia'=>'🇿🇲','china'=>'🇨🇳','france'=>'🇫🇷','germany'=>'🇩🇪','ireland'=>'🇮🇪','japan'=>'🇯🇵','mexico'=>'🇲🇽','netherlands'=>'🇳🇱','taiwan'=>'🇹🇼','united-states'=>'🇺🇸']; return $flags[$slug]??'🌐'; }
 private static function countries() {
  $terms=get_terms(['taxonomy'=>self::TAX,'hide_empty'=>false]);
  if(is_wp_error($terms)) return [];
  $priority=['canada'=>0,'australia'=>1,'new-zealand'=>2,'united-kingdom'=>3,'uk'=>3];
  $slugs=array_map(function($t){return $t->slug;},$terms);
  usort($terms,function($a,$b)use($priority){return (($priority[$a->slug]??99)<=>($priority[$b->slug]??99))?:strcasecmp($a->name,$b->name);});
  $out=[];
  foreach($terms as $t){
   $core=isset($priority[$t->slug]);
   // Prefer the canonical UK slug for empty tiles if both aliases exist.
   if($t->slug==='uk' && in_array('united-kingdom',$slugs,true)) $core=false;
   if(!$core && !$t->count) continue;
   $a=self::base(); self::add_term($a,self::TAX,$t->slug);
   $a['posts_per_page']=1; $a['fields']='ids';
   $a['update_post_meta_cache']=false; $a['update_post_term_cache']=false;
   $q=new WP_Query($a); $count=(int)$q->found_posts;
   if($core || $count>0) $out[]=[$t,$count];
  }
  return $out;
 }
 private static function categories($country) {
  $a=self::base(); self::add_term($a,self::TAX,$country);
  $a['posts_per_page']=-1; $a['fields']='ids'; $a['no_found_rows']=true;
  $a['orderby']='none'; $a['update_post_meta_cache']=false; $a['update_post_term_cache']=false;
  $q=new WP_Query($a); $ids=[];
  foreach(array_chunk($q->posts,500) as $chunk) {
   $terms=wp_get_object_terms($chunk,'product_cat',['fields'=>'ids']);
   if(!is_wp_error($terms)) foreach($terms as $id) $ids[(int)$id]=true;
  }
  foreach(array_keys($ids) as $id) foreach(get_ancestors($id,'product_cat','taxonomy') as $parent) $ids[(int)$parent]=true;
  if(!$ids) return [];
  $terms=get_terms(['taxonomy'=>'product_cat','include'=>array_keys($ids),'hide_empty'=>false,'orderby'=>'name']);
  if(is_wp_error($terms)) return [];
  $tree=[]; foreach($terms as $t) $tree[(int)$t->parent][]=$t;
  $out=[];
  $walk=function($parent,$depth)use(&$walk,&$out,$tree){
   foreach($tree[$parent]??[] as $t) {
    $out[]=['value'=>$t->slug,'label'=>str_repeat('— ',$depth).$t->name];
    $walk((int)$t->term_id,$depth+1);
   }
  };
  $walk(0,0); return $out;
 }
 private static function render($q,$f=[]) {
  $oldloop=$GLOBALS['woocommerce_loop']??null; $oldproduct=$GLOBALS['product']??null; $oldpost=$GLOBALS['post']??null;
  wc_setup_loop(['columns'=>4,'name'=>'czk-marketplace','is_shortcode'=>true,'total'=>$q->found_posts,'total_pages'=>$q->max_num_pages,'per_page'=>12,'current_page'=>max(1,$q->get('paged')),'is_paginated'=>false]);
  ob_start();
  if($q->have_posts()) { echo '<div class="woocommerce columns-4">'; woocommerce_product_loop_start(); while($q->have_posts()){ $q->the_post(); wc_setup_product_data(get_the_ID()); wc_get_template_part('content','product'); } woocommerce_product_loop_end(); echo '</div>'; }
  else {
    $country=$f['country']??'';
    $message=$country!==''?'No products match these filters. Try clearing your filters.':'No products match these filters. Try another country or search.';
    if ($country!=='' && empty($f['search']) && empty($f['category']) && empty($f['status'])) {
     $term=get_term_by('slug',$country,self::TAX);
     if ($term instanceof WP_Term) $message='No products from '.$term->name.' are available just yet.';
    }
    echo '<p class="czk-empty">'.esc_html($message).'</p>';
   }
  $html=ob_get_clean(); wp_reset_postdata(); $GLOBALS['post']=$oldpost; if($oldpost instanceof WP_Post) setup_postdata($oldpost); $GLOBALS['product']=$oldproduct;
  if($oldloop===null) wc_reset_loop(); else $GLOBALS['woocommerce_loop']=$oldloop;
  return $html;
 }
 public static function ajax() {
  if(!self::ready()) wp_send_json_error(['message'=>'The marketplace is temporarily unavailable.'],503);
  // Public read-only catalogue endpoint. No account, checkout or order data is returned.
  $f=self::clean($_POST);
  $categories=null;
  if(isset($_POST['refresh_categories']) && $_POST['refresh_categories']==='1') {
   $categories=self::categories($f['country']);
   if($f['category']!==''&&!in_array($f['category'],array_column($categories,'value'),true)) $f['category']='';
  }
  $q=self::query($f); wp_send_json_success(['html'=>self::render($q,$f),'total'=>(int)$q->found_posts,'pages'=>(int)$q->max_num_pages,'page'=>$f['page'],'categories'=>$categories,'category'=>$f['category']]);
 }
 private static function archive_country() {
  if (is_tax(self::TAX)) {
   $term = get_queried_object();
   if ($term instanceof WP_Term && $term->taxonomy === self::TAX) return $term->slug;
  }
  return '';
 }
 private static function headings($country) {
  $headings = [
   'canada'=>['Shop Canada','Discover products from the True North.'],
   'australia'=>['Shop Australia','Discover products from across the Land Down Under.'],
   'new-zealand'=>['Shop New Zealand','Discover products from Aotearoa, the Land of the Long White Cloud.'],
   'united-kingdom'=>['Shop the United Kingdom','Discover products from across the United Kingdom.'],
   'uk'=>['Shop the United Kingdom','Discover products from across the United Kingdom.'],
  ];
  if (isset($headings[$country])) return $headings[$country];
  if ($country !== '') {
   $term = get_term_by('slug',$country,self::TAX);
   if ($term instanceof WP_Term) return ['Shop '.$term->name,'Discover products from '.$term->name.'.'];
  }
  return ['Shop the marketplace','Discover products from across the Commonwealth.'];
 }
 public static function shortcode() {
  if(!self::ready()) return current_user_can('manage_woocommerce')?'CANZUKON filter requires WooCommerce and the Country of Origin attribute.':'';
  wp_enqueue_style('czk-marketplace'); wp_enqueue_script('czk-marketplace');
  if(get_option('woocommerce_enable_ajax_add_to_cart')==='yes') wp_enqueue_script('wc-add-to-cart');
  $country=self::archive_country();
  $heading=self::headings($country);
  $q=self::query(self::clean(['country'=>$country]));
  $countries=$country===''?self::countries():[]; $categories=self::categories($country);
  ob_start(); ?>
  <section class="czk-market" data-endpoint="https://canzukon.ca/wp-admin/admin-ajax.php" data-fixed-country="">
   <header class="czk-heading"><h2></h2><p></p></header>
      <form class="czk-controls" role="search" aria-label="Marketplace product filters">
    <label class="czk-search"><svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true"><circle cx="10.5" cy="10.5" r="7.5"/><path d="m16 16 5 5"/></svg><input type="search" name="search" placeholder="Search these products..." aria-label="Search these products" maxlength="100"></label>
    <div class="czk-selects">
     <select name="category" aria-label="Product category"><option value="">All categories</option></select>
     <select name="status" aria-label="Product status"><option value="">All products</option><option value="featured">Featured</option><option value="sale">On sale</option><option value="stock">In stock</option></select>
    </div>
    <div class="czk-sort"><select name="sort" aria-label="Sort products"><option value="default">Default sorting</option><option value="newest">Newest arrivals</option><option value="price-low">Price: low to high</option><option value="price-high">Price: high to low</option><option value="popular">Best selling</option><option value="rated">Highest rated</option></select><button type="button" class="czk-clear" hidden>Clear filters</button></div>
   </form>
   <div class="czk-meta"><span class="czk-count" role="status" aria-live="polite">0 products</span></div>
   <div class="czk-active" aria-label="Active filters" hidden></div><?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//canzukon.ca/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://canzukon.ca/page-sitemap.xml</loc>
		<lastmod>2026-11-27T01:05:29+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://canzukon.ca/product-sitemap.xml</loc>
		<lastmod>2026-11-27T13:55:40+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://canzukon.ca/product_cat-sitemap.xml</loc>
		<lastmod>2026-11-27T13:55:40+00:00</lastmod>
	</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Rank Math SEO Plugin (c) Rank Math - rankmath.com -->