المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : ووردبريس WordPress ووكومرس WooCommerce قائمة المدن Cities drop down



Rise Company
15-03-2022, 02:20
ووردبريس WordPress ووكومرس WooCommerce قائمة المدن Cities drop down
3 Level WooCommerce States & Cities drop down - Plugin Development in WordPress
How to add custom country in WooCommerce - How to add city and districts in WooCommerce
Replace the city text field by a dropdown of cities for a specific country in Woocommerce
Add dropdown list of cities in Woocommerce checkout page
Aramex: ERR52 - Destination Address - City name is invalid (s)

https://youtu.be/yGhB5zRXUos

الروابط
https://github.com/YTTechiePress/states-and-cities-for-woocommerce/blob/main/states-and-cities-for-wocoommerce.php
https://github.com/woocommerce/woocommerce/blob/master/i18n/countries.php
https://github.com/woocommerce/woocommerce/blob/master/i18n/states.php

In some specific cases, you might need to change the WooCommerce default country, state or region to better suit your needs. For example, if you are creating a city-specific service that delivers the orders only inside the city boundaries.
Woocommerce comes with the predefined country list as well as the states and regions. However, this list is not so accurate as you might need to limit the shipping zone to the city districts or municipalities.

The code need to be added in your theme's function.php file. There is no problems with this answer code as it's fully tested and works. You can also use the Code Snippets plugin (https://wordpress.org/plugins/code-snippets/) that woocommerce recommend. Using the theme editor is not recommended. You should use an external editor linked to your FTP software.



// Copy from here

/**
* Change the checkout city field to a dropdown field.
*/
function jeroen_sormani_change_city_to_dropdown( $fields ) {

$city_args = wp_parse_args( array(
'type' => 'select',
'options' => array(
'alexandria' => 'Alexandria',
'Awaied-Ras Souda' => 'Awaied-Ras Souda',
'Borg Al Arab City' => 'Borg Al Arab City',
'Sedi Kreir' => 'Sedi Kreir',
'Atfeah' => 'Atfeah',
'Badrashin' => 'Badrashin',
),
'input_class' => array(
'wc-enhanced-select',
)
), $fields['shipping']['shipping_city'] );

$fields['shipping']['shipping_city'] = $city_args;
$fields['billing']['billing_city'] = $city_args; // Also change for billing field

wc_enqueue_js( "
jQuery( ':input.wc-enhanced-select' ).filter( ':not(.enhanced)' ).each( function() {
var select2_args = { minimumResultsForSearch: 5 };
jQuery( this ).select2( select2_args ).addClass( 'enhanced' );
});" );

return $fields;

}
add_filter( 'woocommerce_checkout_fields', 'jeroen_sormani_change_city_to_dropdown' );

ضع الكود داخل functions.php فى theme child او ضعها فى Code Snippets plugin (https://wordpress.org/plugins/code-snippets/)
الكود فى الاعلى كل ما عليك فعله هو وضع city بداخلها
بالترتيب الى تريده مع القيمة ويقابلها اللغة

ملحوظة :
اهمية عمل ذلك هو ان اراميكس لها توزيعة محددة فى حساب shipping
يتطلب ان يكون cities الخاصة بها موجودة كاختيار select لان البديل
هيكون العميل يكتب text اسم city والتى يجب ان تكون متطابقة تماما مع aramex
وحرف زائد او مسافة زائدة هيجب rate calculate يكون خطا
Aramex: ERR52 - Destination Address - City name is invalid (s)

فى المرفقات ملف أرامكس بالتقسيم المعتمد لهم

المرجع:
https://silvawebdesigns.com/how-to-change-the-city-field-to-a-dropdown-in-woocommerce/
https://stackoverflow.com/questions/47013836/add-dropdown-list-of-cities-in-woocommerce-checkout-page
https://stackoverflow.com/questions/52605635/replace-the-city-text-field-by-a-dropdown-of-cities-for-a-specific-country-in-wo
https://stackoverflow.com/questions/61896219/aramex-plugin-errors
https://wordathemes.com/add-city-and-district-for-shipping-zones-in-woocommerce/
https://aceplugins.com/how-to-make-the-customer-city-field-a-dropdown/
https://xtemos.com/forums/topic/dropdown-for-woocommerce-checkout/

Rise Company
28-03-2022, 03:42
/**
* Change the checkout city field to a dropdown field.
*/
function jeroen_sormani_change_city_to_dropdown( $fields ) {

$city_args = wp_parse_args( array(
'type' => 'select',
'options' => array(
/*alex*/
'Alexandria' => 'الإسكندرية Alexandria',
'Awaied-Ras Souda' => 'عوايد راس سودا Awaied-Ras Souda',
'Borg Al Arab City' => 'برج العرب Borg Al Arab City',
'Sedi Kreir' => 'سيدي كرير Sedi Kreir',
/*giza*/
'Giza' => 'الجيزة Giza',
'Abo Rawash' => 'أبو رواش Abo Rawash',
'Agouza' => 'العجوزة Agouza',
'Al Haram' => 'الهرم Al Haram',
'Al Monib' => 'المنيب Al Monib',
'Wahat' => 'الواحات Wahat',
'Al Waraq' => 'الوراق Al Waraq',
'Alex Desert Rd.' => 'طريق اسكندرية الصحراوى Alex Desert Rd.',
'Atfeah' => 'اطفيح Atfeah',
'Badrashin' => 'البدرشين Badrashin',
'Bahtem' => 'بهتيم Bahtem',
'Bargiel' => 'براجيل Bargiel',
'Bolak El Dakrour' => 'بولاق الدكرور Bolak El Dakrour',
'Dahshour' => 'دهشور Dahshour',
'Dokki' => 'الدقي Dokki',
'El Ayat' => 'العياط El Ayat',
'El Hawamdiah' => 'الحوامدية El Hawamdiah',
'EL Korimat' => 'الكريمات EL Korimat',
'El Saf' => 'الصف El Saf',
'Imbaba' => 'إمبابة Imbaba',
'Manial El Rodah' => 'منيل الروضة Manial El Rodah',
'Mohandiseen' => 'المهندسين Mohandiseen',
'October City' => 'مدينة اكتوبر October City',
'Omranya' => 'العمرانية Omranya',
'Saqara' => 'سقارة Saqara',
'Zamalek' => 'الزمالك Zamalek',
/*cairo*/
'15 Of May City' => 'مدينة 15 مايو 15 Of May City',
'Abasya' => 'العباسية Abasya',
'Ain Shams' => 'عين شمس Ain Shams',
'Al Marg' => 'المرج Al Marg',
'Al Matarya' => 'المطرية Al Matarya',
'Al Shorouk' => 'الشروق Al Shorouk',
'Attaba' => 'العتبة Attaba',
'Badr City' => 'مدينة بدر Badr City',
'Cornish El Nile' => 'كورنيش النيل Cornish El Nile',
'Dar El Salam' => 'دار السلام Dar El Salam',
'Down Town' => 'وسط البلد Down Town',
'El Maadi' => 'المعادي El Maadi',
'El Marg' => 'المرج El Marg',
'EL rehab' => 'الرحاب EL rehab',
'El Salam City' => 'مدينة السلام El Salam City',
'EL SAWAH' => 'السواح EL SAWAH',
'El Zeitoun' => 'الزيتون El Zeitoun',
'Garden City' => 'جاردن سيتي Garden City',
'Ghamrah' => 'غمره Ghamrah',
'Hadayek El Qobah' => 'حدائق القبة Hadayek El Qobah',
'Heliopolis' => 'مصر الجديدة Heliopolis',
'Helwan' => 'حلوان Helwan',
'Kasr El Einy' => 'القصر العيني Kasr El Einy',
'Katamiah' => 'القطامية Katamiah',
'Maadi' => 'المعادي Maadi',
'Madinaty' => 'مدينتي Madinaty',
'Mansheyt Naser' => 'منشية ناصر Mansheyt Naser',
'Mokattam' => 'المقطم Mokattam',
'Nasr City' => 'مدينة نصر Nasr City',
'New Cairo' => 'القاهرة الجديدة New Cairo',
'New Capital City' => 'العاصمة الادارية الجديدة New Capital City',
'Ramsis' => 'رمسيس Ramsis',
'Shubra' => 'شبرا Shubra',
'Tebin' => 'التبين Tebin',
'Torah' => 'طره Torah',
/*Beheira*/
'Al Nobariah' => 'النوبارية Al Nobariah',
'Damanhour' => 'دمنهور Damanhour',
'Wadi El Natroun' => 'وادي النطرون Wadi El Natroun',
/*Sharqia*/
'10Th Of Ramadan City' => 'العاشر من رمضان 10Th Of Ramadan City',
/*Aswan*/
'ABOU SOMBO' => 'أبو سمبل ABOU SOMBO',
'Aswan' => 'أسوان Aswan',
'High Dam' => 'السد عالي High Dam',
/*Qaliubia*/
'Abu Zaabal' => 'أبو زعبل Abu Zaabal',
'Al Obour City' => 'مدينة العبور Al Obour City',
'AL Qanater' => 'القناطر AL Qanater',
'Beigam' => 'بيجام Beigam',
'Benha' => 'بنها',
/*Red Sea*/
'Al Arish' => 'العريش Al Arish',
'EL GOUNA' => 'الجونة EL GOUNA',
'Hurghada' => 'الغردقة Hurghada',
'Marsa Alam' => 'مرسى علم Marsa Alam',
'RAS GHAREB' => 'راس غارب RAS GHAREB',
'Ras Shoqeir' => 'راس شقير Ras Shoqeir',
'Safaga' => 'سفاجا Safaga',
/*Gharbia*/
'Al Mahala' => 'المحلة Al Mahala',
'Tanta' => 'طنطا Tanta',
/*Al Menofiah*/
'Al Menofiah' => 'المنوفية Al Menofiah',
'Berkeit Sabb' => 'بركة السبع Berkeit Sabb',
'Quesna' => 'قويسنا Quesna',
'Sadat City' => 'مدينة السادات Sadat City',
'Shebin El Koum' => 'شبين الكوم Shebin El Koum',
/*Bani Swif*/
'Bani Swif' => 'بني سويف Bani Swif',
/*Daqahlia*/
'Belqas' => 'بلقاس Belqas',
'Mansoura' => 'المنصورة Mansoura',
'Meet Ghamr' => 'ميت غمر Meet Ghamr',
/*Kafr Al Sheikh*/
'Kafr Al Sheikh' => 'كفر الشيخ Kafr Al Sheikh',
'Desouk' => 'دسوق Desouk',
/*Dumiatta*/
'Dumiatta' => 'دمياط Dumiatta',
/*Suez*/
'Suez' => 'السويس Suez',
'Ein Al Sukhna' => 'العين السخنة Ein Al Sukhna',
'El Qantara Sharq' => 'القنطرة شرق El Qantara Sharq',
/*New Valley*/
'El Wadi El Gadid' => 'الوادى الجديد El Wadi El Gadid',
'Toshka' => 'توشكى Toshka',
/*Ismailia*/
'Fayid' => 'فايد Fayid',
'Ismailia' => 'الإسماعيلية Ismailia',
/*Fayoum*/
'Fayoum' => 'الفيوم',
/*Luxour*/
'Luxour' => 'الاقصر Luxour',
/*Marsa Matrouh*/
'Marabella' => 'ماربيلا Marabella',
'Maraqia' => 'مراقيا Maraqia',
'Marinah' => 'مارينا Marinah',
'Marsa Matrouh' => 'مرسى مطروح Marsa Matrouh',
'Siwa' => 'سيوة Siwa',
/*Menia*/
'Menia City' => 'مدينة المنيا Menia City',
/*Qena*/
'Qena' => 'قنا Qena',
'Nag Hamadi' => 'نجع حمادي Nag Hamadi',
/*Port Said*/
'Port Said' => 'بورسعيد Port Said',
/*South Sinai*/
'Al Tour City' => 'مدينة الطور Al Tour City',
'Dahab City' => 'مدينة دهب Dahab City',
'Nuwibaa' => 'نويبع Nuwibaa',
'Ras Seidr' => 'راس سدر Ras Seidr',
'Sharm El Sheikh' => 'شرم الشيخ Sharm El Sheikh',
'Taba City' => 'مدينة طابا Taba City',
/*North Sinai*/
'Rafah' => 'رفح Rafah',
/*Sohag*/
'Sohag City' => 'مدينة سوهاج Sohag City',
/*Assiut*/
'Assiut' => 'أسيوط Assiut',

),
'input_class' => array(
'wc-enhanced-select',
)
), $fields['shipping']['shipping_city'] );

$fields['shipping']['shipping_city'] = $city_args;
$fields['billing']['billing_city'] = $city_args; // Also change for billing field

wc_enqueue_js( "
jQuery( ':input.wc-enhanced-select' ).filter( ':not(.enhanced)' ).each( function() {
var select2_args = { minimumResultsForSearch: 5 };
jQuery( this ).select2( select2_args ).addClass( 'enhanced' );
});" );

return $fields;

}
add_filter( 'woocommerce_checkout_fields', 'jeroen_sormani_change_city_to_dropdown' );