We’re always here to help , Contact our support team 24/7.
WhatsApp us
document.addEventListener('DOMContentLoaded', function() {
// تحديد الروابط بناءً على الثمن وكود الدولة
// **مهم جدا: قم بتغيير هذه الروابط إلى الروابط الحقيقية لمنتجاتك!**
const planUrls = {
'39.99': {
'MA': 'https://your-domain.com/link-for-39.99-morocco', // غير هاد الرابط للمغرب (39.99)
'US': 'https://your-domain.com/link-for-39.99-usa' // غير هاد الرابط لأمريكا (39.99)
},
'59.99': {
'MA': 'https://your-domain.com/link-for-59.99-morocco', // غير هاد الرابط للمغرب (59.99)
'US': 'https://your-domain.com/link-for-59.99-usa' // غير هاد الرابط لأمريكا (59.99)
},
'99.99': {
'MA': 'https://your-domain.com/link-for-99.99-morocco', // غير هاد الرابط للمغرب (99.99)
'US': 'https://your-domain.com/link-for-99.99-usa' // غير هاد الرابط لأمريكا (99.99)
},
'140.99': {
'MA': 'https://your-domain.com/link-for-140.99-morocco', // غير هاد الرابط للمغرب (140.99)
'US': 'https://your-domain.com/link-for-140.99-usa' // غير هاد الرابط لأمريكا (140.99)
}
// أضف المزيد من الباقات هنا إذا كانت لديك (بنفس التنسيق)
};
// الرابط الافتراضي الذي سيتم استخدامه إذا لم يتم العثور على رابط خاص للدولة أو في حالة وجود خطأ
const defaultFallbackUrl = 'https://your-domain.com/default-product-link'; // **غير هاد الرابط الافتراضي العام**
// البحث عن جميع Elementor Price Table widgets في الصفحة
const priceTableWidgets = document.querySelectorAll('.elementor-widget-price-table');
// إذا لم يتم العثور على أي Price Table widgets، توقف عن تنفيذ السكريبت
if (priceTableWidgets.length === 0) {
// console.warn('Elementor Price Table widgets not found. The script will not execute.'); // هاد السطر كتحيدو في الإنتاج
return;
}
// جلب معلومات الدولة من IPAPI.co
fetch('https://ipapi.co/json/')
.then(response => {
if (!response.ok) {
// إذا كان هناك مشكل في الرد من الـ API، أرمي خطأ
throw new Error('Network response was not ok from IP API');
}
return response.json();
})
.then(data => {
const countryCode = data.country_code; // كود الدولة (مثال: MA, US)
// المرور على كل Price Table widget
priceTableWidgets.forEach(widget => {
// البحث عن عنصر الثمن داخل الـ widget (span.elementor-price-table__integer-part)
const priceElement = widget.querySelector('.elementor-price-table__integer-part');
// البحث عن زر "BUY NOW" داخل الـ widget (a.elementor-price-table__button)
const buyButton = widget.querySelector('.elementor-price-table__button');
// إذا لقينا عنصر الثمن وزر الشراء
if (priceElement && buyButton) {
// استخراج الثمن كرقم عشري (مثال: "39.99" -> 39.99)
let planPrice = parseFloat(priceElement.textContent.trim());
let redirectUrl = defaultFallbackUrl; // تعيين الرابط الافتراضي كبداية
// التحقق مما إذا كان هناك رابط خاص لهذا الثمن ولهذه الدولة
if (planUrls[planPrice]) {
if (planUrls[planPrice][countryCode]) {
redirectUrl = planUrls[planPrice][countryCode];
} else {
// إذا لم يتم العثور على رابط لدولة محددة لهذا الثمن
// console.warn(`No specific URL found for country ${countryCode} for plan ${planPrice}. Using fallback link.`); // كتحيدو في الإنتاج
}
} else {
// إذا لم يتم العثور على الثمن في قائمة planUrls (مثلا ثمن جديد لم يتم إضافته)
// console.warn(`URL mapping for plan price ${planPrice} not found in planUrls object.`); // كتحيدو في الإنتاج
}
buyButton.href = redirectUrl; // تحديث الرابط ديال زر "BUY NOW"
} else {
// إذا لم يتم العثور على عنصر الثمن أو زر الشراء في widget معين
// console.warn('Price element or buy button not found within a specific price table widget. Skipping.'); // كتحيدو في الإنتاج
}
});
})
.catch(error => {
// في حالة وجود أي خطأ أثناء جلب معلومات IP أو تحديث الروابط
// console.error('An error occurred during geolocation or link update:', error); // كتحيدو في الإنتاج
// قم بتعيين الرابط الافتراضي لجميع أزرار الشراء في حالة وجود خطأ
const allBuyButtons = document.querySelectorAll('.elementor-price-table__button');
allBuyButtons.forEach(button => {
button.href = defaultFallbackUrl;
});
});
});