/** * Client-side fix for My Account → My Points “worth …” line. * The app renders via JS, so we patch it in the browser. */ add_action('wp_enqueue_scripts', function () { if (!function_exists('is_account_page') || !is_account_page()) return; if (!function_exists('is_wc_endpoint_url') || !is_wc_endpoint_url('my-points')) return; $currency = kaizer_curr(); // 1 USD → current currency (AED) using Curcy so it matches site rates/fees $unit_rate = function_exists('wmc_get_price') ? (float) wmc_get_price(1, $currency) : 1.0; $symbol = get_woocommerce_currency_symbol($currency); $decimals = wc_get_price_decimals(); $thousand = wc_get_price_thousand_separator(); $decimal = wc_get_price_decimal_separator(); $js = << 0 ? n.toFixed(DECIMALS) : Math.round(n).toString()); var p = fixed.split('.'); p[0] = p[0].replace(/\\B(?=(\\d{3})+(?!\\d))/g, THOUS); return SYMBOL + ' ' + p[0] + (DECIMALS > 0 ? DEC + p[1] : ''); } function fix() { var el = document.querySelector('.points-worth-text'); if (!el) return; // In: You have 272 points (worth AED 27). var strongs = el.querySelectorAll('strong'); if (strongs.length < 2) return; // Parse the USD amount that plugin printed (it shows "AED 27" but value is USD). var usdText = strongs[1].textContent.replace(/[^0-9.,]/g, ''); if (!usdText) return; var usd = parseFloat(usdText.replace(',', '.')); if (isNaN(usd)) return; var converted = usd * RATE; strongs[1].textContent = formatCurrency(converted); } // Run once after DOM is ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', fix); } else { fix(); } // Also watch for SPA/React updates inside the account app var mo = new MutationObserver(function(){ fix(); }); mo.observe(document.body, { childList: true, subtree: true }); })(); JS; // Attach after core (no dependency on jQuery) wp_add_inline_script('jquery-core', $js, 'after'); });