Woocommerce panelinde bulunan şahıs şirketi ve kurumsal şirket siparişlerinize Veri girmeye yarar.
Mustafa Özdemir tarafından yazıldı
UYARI: AŞAĞIDAKİ AYARLAR YAPILMADAN ÖNCE SİTENİZİN YEDEĞİNİ MUTLAKA ALINIZ. BU İŞLEMLER SONUCUNDA DOĞAN HERHANGİ BİR PROBLEMDEN DOLAYI HİÇBİR ŞEKİLDE TARAFIMIZCA MESULİYET KABUL EDİLMEMEKTEDİR.
Öncelikle Wordpress admin panelinize giriş yapınız.
Sonrasında Görünüm > Tema Dosya Düzenleyeci > adımlarına takip ediniz.
Aşağıdaki kodu functions.php dosyasının en sonuna ekleyiniz ve dosyayı güncelle deyiniz.
NOT: Bu işlemleri yaparken temanızın child temasını kullanınız. Aksi taktirde temanıza bir güncelleme geldiğinde bu kod silinecektir ve tekrardan bu ayarları yapmanız gerekmektedir.
function custom_override_checkout_fields( $fields ) { unset($fields['billing']['billing_address_2']); unset($fields['billing']['billing_country']); unset($fields['billing']['billing_postcode']); unset($fields['billing']['billing_company']); unset($fields['order']['order_comments']); $fields['billing']['billing_address_1']['label'] = 'Adres'; $fields['billing']['billing_address_1']['placeholder'] = 'Mahalle, Sokak, Bina No, Daire vb.'; $fields['billing']['billing_address_1']['priority'] = '90'; $fields['billing']['billing_first_name']['placeholder'] = 'Ad'; $fields['billing']['billing_first_name']['label'] = 'Ad'; $fields['billing']['billing_last_name']['placeholder'] = 'Soyad'; $fields['billing']['billing_last_name']['label'] = 'Soyad'; $fields['billing']['billing_city']['label'] = 'İlçe'; $fields['billing']['billing_city']['placeholder'] = 'İlçe'; unset($fields['shipping']['shipping_address_2']); unset($fields['shipping']['shipping_country']); unset($fields['shipping']['shipping_postcode']); unset($fields['shipping']['shipping_company']); $fields['shipping']['shipping_address_1']['label'] = 'Adres'; $fields['shipping']['shipping_address_1']['priority'] = '90'; $fields['shipping']['shipping_city']['label'] = 'İlçe'; $fields['shipping']['shipping_city']['placeholder'] = 'İlçe'; $fields['shipping']['shipping_address_1']['placeholder'] = 'Mahalle, Sokak, Bina No, Daire vb.'; $fields['shipping']['shipping_first_name']['placeholder'] = 'Ad'; $fields['shipping']['shipping_first_name']['label'] = 'Ad'; $fields['shipping']['shipping_last_name']['placeholder'] = 'Soyad'; $fields['shipping']['shipping_last_name']['label'] = 'Soyad'; return $fields; } add_filter('woocommerce_checkout_fields','custom_override_checkout_fields'); add_filter( 'woocommerce_enable_order_notes_field', '__return_false', 9999 );
// T.C. No, Vergi No ve Vergi Dairesi Alanlarını Oluştur
add_filter('woocommerce_checkout_fields', 'tc_vergi_icin_new_checkout_field'); function tc_vergi_icin_new_checkout_field($fields) { $fields['billing']['checkbox_tckno'] = array( 'type' => 'checkbox', 'priority' => 5, 'label' => __('TC Kimlik No', 'woocommerce'), 'class' => array('form-row-left'), 'clear' => true ); $fields['billing']['checkbox_trigger'] = array( 'type' => 'checkbox', 'priority' => 8, 'label' => __('Kurumsal Fatura', 'woocommerce'), 'class' => array('form-row-right'), 'clear' => true ); $fields['billing']['billing_tc_kimlik_no'] = array( 'label' => __('Vergi / TC Kimlik No', 'woocommerce'), 'placeholder' => _x('Vergi No', 'placeholder', 'woocommerce'), 'class' => array('form-row form-row-last'), 'required' => true, 'priority' => 31, 'clear' => true ); $fields['billing']['billing_vergi_dairesi'] = array( 'label' => __('Vergi Dairesi', 'woocommerce'), 'placeholder' => _x('Vergi Dairesi', 'placeholder', 'woocommerce'), 'class' => array('form-row form-row-first'), 'required' => true, 'priority' => 32, 'clear' => true ); if (!isset($_POST['checkbox_trigger'])) { $fields['billing']['billing_tc_kimlik_no']['required'] = false; $fields['billing']['billing_vergi_dairesi']['required'] = false; } else { $fields['billing']['billing_tc_kimlik_no']['required'] = true; $fields['billing']['billing_vergi_dairesi']['required'] = true; } if (!isset($_POST['checkbox_trigger'])) { $fields['billing']['billing_tc_kimlik_no']['default'] = '11111111111'; } else { $fields['billing']['billing_tc_kimlik_no']['default'] = '11111111111'; } return $fields; }
// TC Doğrula Fonksiyonu
function isTcKimlik($tc) {
// Array içindeki denemeler tc kriterine uyduğu için hariç tuttuk.
$exclude = array('11111111110', '22222222220', '33333333330', '44444444440', '55555555550', '66666666660', '7777777770', '88888888880', '99999999990');
// Bunlar aşağıdaki fonksiyonu yanıltan numaralar dilerseniz kaldırabilirsiniz satırı.
if (in_array($tc, $exclude)) { return false; } if (strlen($tc) < 11) { return false; } if ($tc[0] == '0') { return false; } $plus = ($tc[0] + $tc[2] + $tc[4] + $tc[6] + $tc[8]) * 7; $minus = $plus - ($tc[1] + $tc[3] + $tc[5] + $tc[7]); $mod = $minus % 10; if ($mod != $tc[9]) { return false; } $all = 0; for ($i = 0; $i < 10; $i++) { $all += $tc[$i]; } if ($all % 10 != $tc[10]) { return false; } return true; }
// TC Kimlik Noyu Doğrula
add_action('woocommerce_checkout_process', 'tc_numara_dogrula'); function tc_numara_dogrula() { $tcno = $_POST['shipping_tc']; if (!empty($tcno)) { if (!is_numeric($tcno) && !isset($_POST['checkbox_trigger'])) { wc_add_notice(__('T.C alanına lütfen sayısal bir değer girin yada siparişiniz 5.000,00 TL den küçük ise boş bırakın.'), 'error'); } else if (!empty($tcno) && !isset($_POST['checkbox_trigger'])) { if (!isTcKimlik($tcno)) wc_add_notice(__('Lütfen doğru bir TC kimlik no girin yada siparişiniz 5.000,00 TL den küçük ise boş bırakın.'), 'error'); } } }
// Vergi No Doğrulama Fonksiyonu
function validateTaxNo($taxNo) { if (strlen($taxNo) == 10) { for ($i = 0; $i < 9; $i++) { $v[$i + 1] = ($taxNo[$i] + (9 - $i)) % 10; $vv[$i + 1] = ($v[$i + 1] * pow(2, (9 - $i))) % 9; $vv[$i + 1] = ($v[$i + 1] != 0 && $vv[$i + 1] == 0) ? 9 : $vv[$i + 1]; } $sum = array_sum($vv); $sum = ($sum % 10 == 0) ? 0 : (10 - ($sum % 10)); return ($sum == $taxNo[9]) ? true : false; } return false; }
// Vergi Noyu Doğrula
add_action('woocommerce_checkout_process', 'vergi_no_dogrula'); function vergi_no_dogrula() { $tc_kimlik_no = $_POST['billing_tc_kimlik_no']; if (isset($_POST['checkbox_trigger'])) { if (!validateTaxNo($tc_kimlik_no)) wc_add_notice(__('Lütfen Doğru Bir Vergi No Girin.'), 'error'); } }
// Adminin Sipariş Detayında Fatura Bilgilerinde TC No ve Vergi Dairesi Görebilmesi İçin
add_action('woocommerce_admin_order_data_after_billing_address', 'vergi_no_dairesi', 10, 1); function vergi_no_dairesi($order) { echo '<p><strong>' . __('Vergi / TC Kimlik No') . ':</strong> ' . $tc_kimlik_no = get_post_meta($order->get_id(), '_billing_tc_kimlik_no', true) . '</p>'; echo '<p><strong>' . __('Vergi Dairesi') . ':</strong> ' . $vergi_dairesi = get_post_meta($order->get_id(), '_billing_vergi_dairesi', true) . '</p>'; }
// Koşullara göre alanları göstermek için gerekli javascript kodları
add_action('woocommerce_after_checkout_form', 'kosullu_alan_goster', 6); function kosullu_alan_goster() { ?> <script type="text/javascript"> jQuery('#ship-to-different-address').hide() jQuery('.woocommerce-billing-fields > h3').html('Adres bilgileri'); jQuery('#billing_tc_kimlik_no').hide(); jQuery('#billing_vergi_dairesi').hide(); jQuery('#billing_tc_kimlik_no_field > label').hide(); jQuery('#billing_vergi_dairesi_field > label').hide(); jQuery("#billing_tc_kimlik_no_field > label").append("<abbr class='required' title='gerekli'>*</abbr>"); jQuery("#billing_vergi_dairesi_field > label").append("<abbr class='required' title='gerekli'>*</abbr>"); jQuery('input#checkbox_trigger').change(function() { if (this.checked) { jQuery('.woocommerce-billing-fields > h3').html('Fatura bilgileri'); jQuery("#checkbox_tckno").prop( "checked", false ); jQuery('#billing_tc_kimlik_no').show(); jQuery('#billing_vergi_dairesi').show(); jQuery('#billing_last_name_field').hide(); jQuery('#billing_tc_kimlik_no_field > label').show(); jQuery('#billing_vergi_dairesi_field > label').show(); jQuery('#billing_tc_kimlik_no_field > label > span').remove(); jQuery('#billing_vergi_dairesi_field > label > span').remove(); jQuery('#billing_tc_kimlik_no_field').addClass('validate-required'); jQuery('#billing_vergi_dairesi_field').addClass('validate-required'); jQuery('#billing_first_name_field > label').html('Şirket Ünvanı <abbr class="required" title="gerekli">*</abbr>') jQuery('#billing_tc_kimlik_no').attr("value", "") jQuery('#billing_first_name').attr("placeholder", "Şirket Ünvanı") jQuery('#billing_first_name_field').attr("class", "form-row form-row-first validate-required fullwidth_custom") jQuery('#ship-to-different-address').show() jQuery('#billing_tc_kimlik_no').attr("placeholder", "Vergi No") jQuery('#billing_tc_kimlik_no_field').attr("class", "form-row form-row form-row-last ") jQuery('#billing_tc_kimlik_no_field > label').html('Vergi No <abbr class="required" title="gerekli">*</abbr>') } else { jQuery('.woocommerce-billing-fields > h3').html('Adres bilgileri'); jQuery('#billing_last_name_field').show(); jQuery('#billing_vergi_dairesi').hide(); jQuery('#billing_vergi_dairesi_field > label').hide(); jQuery('#billing_vergi_dairesi').hide(); jQuery('#billing_tc_kimlik_no').hide(); jQuery('#billing_vergi_dairesi_field > label').hide(); jQuery('#billing_tc_kimlik_no_field > label').hide(); jQuery('#billing_first_name_field > label').html('Ad <abbr class="required" title="gerekli">*</abbr>') jQuery('#billing_tc_kimlik_no').attr("value", "11111111111") jQuery('#billing_first_name').attr("placeholder", "Ad") jQuery('#billing_first_name_field').attr("class", "form-row form-row-first validate-required") jQuery('#billing_tc_kimlik_no_field > label').html('TC Kimlik No <abbr class="required" title="gerekli">*</abbr>') jQuery('#ship-to-different-address').hide() } }); jQuery('input#checkbox_tckno').change(function() { if (this.checked) { jQuery( "#checkbox_trigger" ).prop( "checked", false ); jQuery('#billing_tc_kimlik_no').show(); jQuery('#billing_tc_kimlik_no_field > label').show(); jQuery('#billing_tc_kimlik_no_field > label > span').remove(); jQuery('#billing_tc_kimlik_no_field').addClass('validate-required'); jQuery('#billing_tc_kimlik_no').attr("value", "") jQuery('#billing_first_name').attr("placeholder", "Ad") jQuery('#billing_tc_kimlik_no').attr("placeholder", "TC Kimlik No") jQuery('#billing_tc_kimlik_no_field').attr("class", "form-row form-row form-row-last fullwidth_custom ") jQuery('#billing_last_name_field').show() jQuery('#billing_first_name_field > label').html('Ad <abbr class="required" title="gerekli">*</abbr>') jQuery('#billing_vergi_dairesi').hide(); jQuery('#billing_vergi_dairesi_field > label').hide(); jQuery('#billing_vergi_dairesi').hide(); jQuery('#billing_vergi_dairesi_field > label').hide(); jQuery('#billing_first_name_field').attr("class", "form-row form-row-first validate-required") jQuery('#billing_tc_kimlik_no_field > label').html('TC Kimlik No <abbr class="required" title="gerekli">*</abbr>') jQuery('#ship-to-different-address').hide() jQuery('.woocommerce-billing-fields > h3').html('Adres bilgileri'); } else { jQuery('#billing_tc_kimlik_no').hide(); jQuery('#billing_tc_kimlik_no_field > label').hide(); jQuery('#billing_tc_kimlik_no').attr("value", "11111111111") jQuery('#billing_first_name').attr("placeholder", "Ad") jQuery('#billing_tc_kimlik_no').attr("placeholder", "Vergi No") jQuery('#billing_tc_kimlik_no_field').attr("class", "form-row form-row form-row-last ") jQuery('#billing_first_name_field').attr("class", "form-row form-row-first validate-required") jQuery('#billing_last_name_field').show() jQuery('#billing_first_name_field > label').html('Ad <abbr class="required" title="gerekli">*</abbr>') jQuery('#billing_tc_kimlik_no_field > label').html('Vergi No <abbr class="required" title="gerekli">*</abbr>') } }); </script> <?php }