110512, 'K911-002-01'=>10518, 'K911-003-01'=>10520,12 'K110-001-01'=>10261, 'K110-001-02'=>10228, 'K911-001-01'=>10255, 'K110-001-02-1'=>10239);13}1415function gafpa_shopping_product_map() {
return gafpa_eagle_product_map() + array(
'20210002028-1'=>10851, '20210002028-1-1'=>10855,
'20210002028-1-1-1'=>10859, '20210002028-1-1-1-1'=>10860,
'20210002028-1-1-1-1-1'=>10865, '20210002028-1-1-1-1-1-1'=>10877,
'ACPCSB-PL'=>10881);
}
function gafpa_eagle_dual_price($html, $product) {16 if (is_admin() || is_cart() || is_checkout() || !$product ||17 !in_array($product->get_id(), gafpa_shopping_product_map(), true) ||18 !$product->is_type('simple') || '' === $product->get_price() ||19 strpos($html, 'gafpa-eagle-vat-price') !== false) {20 return $html;21 }22 return $html . '
' .23 wc_price(wc_get_price_including_tax($product)) . ' incl. VAT';24}25add_filter('woocommerce_get_price_html', 'gafpa_eagle_dual_price', 30, 2);2627// Fixed supplier expectation confirmed by the store owner on 16 October 2026.28// Never roll this forward automatically or imply stock has arrived.29function gafpa_eagle_backorder_date($product) {30 return $product && $product->get_id() === 10255 && $product->is_on_backorder()31 ? '2026-10-30T00:00:00+01:00' : '';32}33function gafpa_eagle_availability_text($text, $product) {34 return gafpa_eagle_backorder_date($product)35 ? 'Available on backorder. Expected availability: 30 October 2026.' : $text;36}
add_filter('woocommerce_get_availability_text', 'gafpa_eagle_availability_text', 30, 2);
function gafpa_eagle_offer_price($offer, $product) {
if (!$product || !in_array($product->get_id(), gafpa_eagle_product_map(), true) ||
!$product->is_type('simple') || '' === $product->get_price()) return $offer;
$gross=number_format(wc_get_price_including_tax($product),2,'.','');
foreach (array('price','lowPrice','highPrice') as $key) {
if (isset($offer[$key])) $offer[$key]=$gross;
}
if (isset($offer['priceSpecification']['price'])) {
$offer['priceSpecification']['price']=$gross;
$offer['priceSpecification']['valueAddedTaxIncluded']=true;
}
return $offer;
}
add_filter('woocommerce_structured_data_product_offer', 'gafpa_eagle_offer_price', 30, 2);
function gafpa_eagle_schema($data) {
if (!function_exists('is_product') || !is_product()) return $data;
$id=get_queried_object_id();
if (!in_array($id,gafpa_eagle_product_map(),true)) return $data;
$product=wc_get_product($id);
foreach ($data as &$node) {
if (!is_array($node) || !isset($node['@type']) ||
!in_array('Product',(array)$node['@type'],true) || !isset($node['offers'])) continue;
if (isset($node['offers']['@type'])) {
$node['offers']=gafpa_eagle_offer_price($node['offers'],$product);
} else {
foreach ($node['offers'] as &$offer) {
if (is_array($offer)) $offer=gafpa_eagle_offer_price($offer,$product);
}
unset($offer);
}
}
unset($node);
return $data;
}
add_filter('rank_math/json_ld','gafpa_eagle_schema',30);
function gafpa_eagle_transform_feed($xml, $products) {
$previous = libxml_use_internal_errors(true);
$doc = new DOMDocument();
$loaded = $doc->loadXML($xml, LIBXML_NONET);
libxml_clear_errors();
libxml_use_internal_errors($previous);
if (!$loaded || $doc->doctype || $doc->documentElement->tagName !== 'rss') return false;
$ns = 'http://base.google.com/ns/1.0';
$map = gafpa_eagle_product_map();
foreach ($doc->getElementsByTagName('item') as $item) {
$id = $item->getElementsByTagNameNS($ns, 'id')->item(0);
if (!$id || !isset($map[strtoupper(trim($id->textContent))])) continue;
$pid = $map[strtoupper(trim($id->textContent))];
if (!isset($products[$pid])) return false;
$p = $products[$pid];
if ($p->get_status() !== 'publish' || !$p->is_type('simple') || $p->get_price() === '') return false;
$values = array(
'brand' => 'Kinefinity',
'price' => number_format(wc_get_price_including_tax($p), 2, '.', '') . ' EUR',
'link' => get_permalink($pid),
'availability' => $p->is_on_backorder() ? 'backorder' : ($p->is_in_stock() ? 'in_stock' : 'out_of_stock'),
);
$availability_date = gafpa_eagle_backorder_date($p);
if ($availability_date) $values['availability_date'] = $availability_date;
foreach ($values as $key=>$value) {
$node = $item->getElementsByTagNameNS($ns, $key)->item(0);
if (!$node) { $node=$doc->createElementNS($ns, 'g:'.$key); $item->appendChild($node); }
while ($node->firstChild) $node->removeChild($node->firstChild);
$node->appendChild($doc->createTextNode($value));
}
// The current live price is already in price. Do not retain an old sale-price override.
foreach (array('sale_price','sale_price_effective_date','ads_redirect') as $key) {
$nodes=$item->getElementsByTagNameNS($ns,$key);
while ($nodes->length) $item->removeChild($nodes->item(0));
}
}
return $doc->saveXML();
}
function gafpa_eagle_shopping_feed() {
if (!isset($_GET['gafpa_eagle_shopping_feed']) || $_GET['gafpa_eagle_shopping_feed'] !== '1') return;
if (!function_exists('wc_get_product') || !class_exists('DOMDocument')) {
status_header(503); exit;
}
$upload=wp_upload_dir();
$path=$upload['basedir'].'/woo-product-feed-pro/xml/Q5J3mqgMlsJjorLmpZbzYCVG60ieWBPF.xml';
if (!is_readable($path) || filemtime($path) < time()-172800) { status_header(503); exit; }
$products=array();
foreach (gafpa_eagle_product_map() as $id) {
$p=wc_get_product($id);
if ($p) $products[$id]=$p;
}
$output=gafpa_eagle_transform_feed(file_get_contents($path),$products);
if ($output===false) { status_header(503); exit; }
nocache_headers();
header('Content-Type: application/xml; charset=UTF-8');
header('X-Robots-Tag: noindex');
echo $output;
exit;
}
add_action('template_redirect', 'gafpa_eagle_shopping_feed', 0);