| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Netgsm |
| 4 |
Plugin URI: https://wordpress.org/plugins/netgsm/ |
| 5 |
Description: Netgsm hesabınız ile Woocommerce müşterileriniz yeni sipariş verdiğinde, yeni kayıt olan müşterileriniz olduğunda ve toplu smslerde kişiye özel ve yöneticilere sms gönderebileceğiniz bir eklentidir. Bunun yanısıra kişiye özel toplu ve özel sms gönderebilir, Gelen kutunuzdaki smsleri anında cevaplaya bilirsiniz. Yeni kayıt olan müşterileriniz netgsm rehberine ekleyebilir, siparişlerin durumları değiştiğinde kargo takip kodu gibi bilgileri müşterilerinize otomatik olarak gönderebilirsiniz. Ayrıca Contact Form 7 formlarınızda sms gönderimi sağlayabilirsiniz. |
| 6 |
Author: Netgsm |
| 7 |
Author URI: www.netgsm.com.tr |
| 8 |
Version: 2.9.75 |
| 9 |
|
| 10 |
|
| 11 |
*/ |
| 12 |
|
| 13 |
/** |
| 14 |
* Copyright (c) 2018 NETGSM Tüm hakları saklıdır. |
| 15 |
* |
| 16 |
* Released under the GPL license |
| 17 |
* http://www.opensource.org/licenses/gpl-license.php |
| 18 |
* |
| 19 |
* This is an add-on for WordPress |
| 20 |
* http://wordpress.org/ |
| 21 |
* |
| 22 |
* ********************************************************************** |
| 23 |
* |
| 24 |
* |
| 25 |
* NETGSM - Yeni Nesil Telekom Operatörü - www.netgsm.com.tr |
| 26 |
* NETGSM - Toplu SMS - Başlıklı SMS - Sabit Telefon - Sanal Santral - 0850li Numara |
| 27 |
* ********************************************************************** |
| 28 |
*/ |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
if (!defined('ABSPATH')) exit; |
| 33 |
|
| 34 |
define('PLUGIN_CLASS_PATH', dirname(__FILE__) . '/includes'); |
| 35 |
require_once PLUGIN_CLASS_PATH . '/netgsmsms.php'; |
| 36 |
require_once PLUGIN_CLASS_PATH . '/replacefunction.php'; |
| 37 |
|
| 38 |
@ini_set('log_errors', 'On'); |
| 39 |
@ini_set('display_errors', 'Off'); |
| 40 |
@ini_set('error_log', 'phperrors.log'); // path to server-writable log file |
| 41 |
|
| 42 |
add_action("admin_menu", "netgsm_addMenuu"); |
| 43 |
function netgsm_addMenuu() |
| 44 |
{ |
| 45 |
add_menu_page("NETGSM - Yeni Nesil Telekom Operatörü - www.netgsm.com.tr", "Netgsm", 'edit_pages', "netgsm-wp-plugin", "netgsm_index", plugins_url('lib/image/netgsm.png', __FILE__)); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
function plugin_name_get_version() |
| 51 |
{ |
| 52 |
$plugin_data = get_plugin_data(__FILE__); |
| 53 |
$plugin_version = $plugin_data['Version']; |
| 54 |
return $plugin_version; |
| 55 |
} |
| 56 |
|
| 57 |
function netgsm_index() |
| 58 |
{ |
| 59 |
|
| 60 |
require_once('pages/index.php'); |
| 61 |
} |
| 62 |
|
| 63 |
add_action('admin_enqueue_scripts', 'netgsm_loadcustomadminstyle'); |
| 64 |
function netgsm_loadcustomadminstyle($hook) |
| 65 |
{ |
| 66 |
if ($hook != 'toplevel_page_netgsm-wp-plugin') { |
| 67 |
return; |
| 68 |
} |
| 69 |
|
| 70 |
$plugin_url = plugin_dir_url(__FILE__); |
| 71 |
wp_enqueue_style('bootstrap', $plugin_url . 'lib/css/bootstrap.css'); |
| 72 |
wp_enqueue_style('font-awesome', $plugin_url . '/lib/fonts/css/font-awesome.min.css'); |
| 73 |
wp_enqueue_style('style', $plugin_url . 'lib/css/style.css'); |
| 74 |
wp_enqueue_style('sweetalert2', $plugin_url . 'lib/js/sweetalert2/dist/sweetalert2.css'); |
| 75 |
wp_enqueue_style('dataTables', $plugin_url . 'lib/css/bootstrap-table.min.css'); |
| 76 |
} |
| 77 |
|
| 78 |
add_action('admin_enqueue_scripts', 'netgsm_script'); |
| 79 |
function netgsm_script() |
| 80 |
{ |
| 81 |
//bootstrap-js YAPMALIYIZ |
| 82 |
wp_register_script('bootstrapminjs', plugins_url('bootstrap.min.js', dirname(__FILE__) . '/lib/js/1/')); |
| 83 |
wp_enqueue_script('bootstrapminjs'); |
| 84 |
|
| 85 |
wp_register_script('sweet2', plugins_url('sweetalert2.all.js', dirname(__FILE__) . '/lib/js/sweetalert2/dist/1/')); |
| 86 |
wp_enqueue_script('sweet2'); |
| 87 |
|
| 88 |
wp_register_script('table', plugins_url('bootstrap-table.min.js', dirname(__FILE__) . '/lib/js/1/')); |
| 89 |
wp_enqueue_script('table'); |
| 90 |
} |
| 91 |
function my_settings_sanitize($input) |
| 92 |
{ |
| 93 |
$replace = new ReplaceFunction(); |
| 94 |
$input = $replace->netgsm_spaceTrim($input); |
| 95 |
return $input; |
| 96 |
} |
| 97 |
|
| 98 |
add_action('admin_init', 'netgsm_options'); |
| 99 |
function netgsm_options() |
| 100 |
{ |
| 101 |
register_setting('netgsmoptions', 'netgsm_user', 'my_settings_sanitize'); |
| 102 |
register_setting('netgsmoptions', 'netgsm_pass'); |
| 103 |
register_setting('netgsmoptions', 'netgsm_input_smstitle'); |
| 104 |
|
| 105 |
register_setting('netgsmoptions', 'netgsm_newuser_to_admin_control'); |
| 106 |
register_setting('netgsmoptions', 'netgsm_newuser_to_admin_no'); |
| 107 |
register_setting('netgsmoptions', 'netgsm_newuser_to_admin_text'); |
| 108 |
register_setting('netgsmoptions', 'netgsm_newuser_to_customer_control'); |
| 109 |
register_setting('netgsmoptions', 'netgsm_newuser_to_customer_text'); |
| 110 |
|
| 111 |
register_setting('netgsmoptions', 'netgsm_neworder_to_admin_control'); |
| 112 |
register_setting('netgsmoptions', 'netgsm_neworder_to_admin_no'); |
| 113 |
register_setting('netgsmoptions', 'netgsm_neworder_to_admin_text'); |
| 114 |
register_setting('netgsmoptions', 'netgsm_neworder_to_customer_control'); |
| 115 |
register_setting('netgsmoptions', 'netgsm_neworder_to_customer_text'); |
| 116 |
|
| 117 |
register_setting('netgsmoptions', 'netgsm_newnote1_to_customer_control'); |
| 118 |
register_setting('netgsmoptions', 'netgsm_newnote1_to_customer_text'); |
| 119 |
|
| 120 |
register_setting('netgsmoptions', 'netgsm_newnote2_to_customer_control'); |
| 121 |
register_setting('netgsmoptions', 'netgsm_newnote2_to_customer_text'); |
| 122 |
|
| 123 |
register_setting('netgsmoptions', 'netgsm_order_refund_to_admin_control'); |
| 124 |
register_setting('netgsmoptions', 'netgsm_order_refund_to_admin_no'); |
| 125 |
register_setting('netgsmoptions', 'netgsm_order_refund_to_admin_text'); |
| 126 |
|
| 127 |
register_setting('netgsmoptions', 'netgsm_abandoned_card_sms_admin_control'); |
| 128 |
register_setting('netgsmoptions', 'netgsm_abandoned_cart_periyod'); |
| 129 |
register_setting('netgsmoptions', 'netgsm_abandoned_cart_smslimit'); |
| 130 |
register_setting('netgsmoptions', 'netgsm_abandoned_cart_to_admin_text'); |
| 131 |
register_setting('netgsmoptions', 'netgsm_abandoned_cart_to_admin_json'); |
| 132 |
|
| 133 |
|
| 134 |
register_setting('netgsmoptions', 'netgsm_product_waitlist1_control'); |
| 135 |
register_setting('netgsmoptions', 'netgsm_product_waitlist1_text'); |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
register_setting('netgsmoptions', 'netgsm_orderstatus_change_customer_control'); |
| 140 |
|
| 141 |
register_setting('netgsmoptions', 'netgsm_status'); |
| 142 |
register_setting('netgsmoptions', 'netgsm_trChar'); |
| 143 |
register_setting('netgsmoptions', 'netgsm_iys_control'); |
| 144 |
|
| 145 |
register_setting('netgsmoptions', 'netgsm_order_status_query_control'); |
| 146 |
register_setting('netgsmoptions', 'netgsm_order_status_query_prefix'); |
| 147 |
register_setting('netgsmoptions', 'netgsm_order_status_query_text'); |
| 148 |
register_setting('netgsmoptions', 'netgsm_order_status_query_error_text'); |
| 149 |
register_setting('netgsmoptions', 'netgsm_order_status_query_token'); |
| 150 |
register_setting('netgsmoptions', 'netgsm_order_status_query_link'); |
| 151 |
|
| 152 |
//JSON settings |
| 153 |
register_setting('netgsmoptions', 'netgsm_newuser_to_admin_json'); |
| 154 |
register_setting('netgsmoptions', 'netgsm_newuser_to_customer_json'); |
| 155 |
register_setting('netgsmoptions', 'netgsm_newnote1_to_customer_json'); |
| 156 |
register_setting('netgsmoptions', 'netgsm_newnote2_to_customer_json'); |
| 157 |
register_setting('netgsmoptions', 'netgsm_neworder_to_admin_json'); |
| 158 |
register_setting('netgsmoptions', 'netgsm_neworder_to_customer_json'); |
| 159 |
register_setting('netgsmoptions', 'netgsm_order_refund_to_admin_json'); |
| 160 |
register_setting('netgsmoptions', 'netgsm_product_waitlist1_json'); |
| 161 |
|
| 162 |
//OTP SMS |
| 163 |
register_setting('netgsmoptions', 'netgsm_tf2_auth_register_control'); |
| 164 |
register_setting('netgsmoptions', 'netgsm_tf2_auth_register_text'); |
| 165 |
register_setting('netgsmoptions', 'netgsm_tf2_auth_register_diff'); |
| 166 |
|
| 167 |
register_setting('netgsmoptions', 'netgsm_tf2_cash_on_delivery_control'); |
| 168 |
register_setting('netgsmoptions', 'netgsm_tf2_cash_on_delivery_text'); |
| 169 |
register_setting('netgsmoptions', 'netgsm_tf2_cash_on_delivery_diff'); |
| 170 |
|
| 171 |
//otp duplicate control |
| 172 |
register_setting('netgsmoptions', 'netgsm_tf2_auth_register_phone_control'); |
| 173 |
register_setting('netgsmoptions', 'netgsm_tf2_auth_register_phone_warning_text'); |
| 174 |
|
| 175 |
//otp ad/soyad zorunlulugu (1 = ad/soyad isteme, sadece numara ile devam et) |
| 176 |
register_setting('netgsmoptions', 'netgsm_tf2_name_optional'); |
| 177 |
|
| 178 |
//contacts meta |
| 179 |
register_setting('netgsmoptions', 'netgsm_contact_meta_key'); |
| 180 |
|
| 181 |
//roles |
| 182 |
register_setting('netgsmoptions', 'netgsm_auth_roles'); |
| 183 |
register_setting('netgsmoptions', 'netgsm_auth_users'); |
| 184 |
register_setting('netgsmoptions', 'netgsm_auth_roles_control'); |
| 185 |
register_setting('netgsmoptions', 'netgsm_auth_users_control'); |
| 186 |
|
| 187 |
register_setting('netgsmoptions', 'netgsm_phonenumber_zero1'); |
| 188 |
register_setting('netgsmoptions', 'netgsm_licence_key_to_meta'); |
| 189 |
|
| 190 |
//ÇIKIŞ |
| 191 |
register_setting('netgsmoptionslogout', 'netgsm_user'); |
| 192 |
register_setting('netgsmoptionslogout', 'netgsm_pass'); |
| 193 |
|
| 194 |
//İYS |
| 195 |
register_setting('netgsmoptions', 'netgsm_iys_check_text'); |
| 196 |
register_setting('netgsmoptions', 'netgsm_iys_check_control'); |
| 197 |
|
| 198 |
register_setting('netgsmoptions', 'netgsm_iys_checkout_control'); |
| 199 |
register_setting('netgsmoptions', 'netgsm_iys_checkout_text'); |
| 200 |
|
| 201 |
register_setting('netgsmoptions', 'netgsm_brandcode_control'); |
| 202 |
register_setting('netgsmoptions', 'netgsm_brandcode_text'); |
| 203 |
register_setting('netgsmoptions', 'netgsm_recipient_type'); |
| 204 |
|
| 205 |
register_setting('netgsmoptions', 'netgsm_message'); |
| 206 |
register_setting('netgsmoptions', 'netgsm_call'); |
| 207 |
register_setting('netgsmoptions', 'netgsm_email'); |
| 208 |
|
| 209 |
register_setting('netgsmoptions', 'netgsm_iys_meta_key'); |
| 210 |
|
| 211 |
|
| 212 |
//ASİSTAN |
| 213 |
|
| 214 |
register_setting('netgsmoptions', 'netgsm_asistan'); |
| 215 |
|
| 216 |
register_setting('netgsmoptions', 'netgsm_asistan_message'); |
| 217 |
register_setting('netgsmoptions', 'netgsm_asistan_messagenumber'); |
| 218 |
|
| 219 |
register_setting('netgsmoptions', 'netgsm_asistan_call'); |
| 220 |
register_setting('netgsmoptions', 'netgsm_asistan_callnumber'); |
| 221 |
|
| 222 |
register_setting('netgsmoptions', 'netgsm_asistan_email'); |
| 223 |
register_setting('netgsmoptions', 'netgsm_asistan_emailaddress'); |
| 224 |
|
| 225 |
register_setting('netgsmoptions', 'netgsm_asistan_whatsapp'); |
| 226 |
register_setting('netgsmoptions', 'netgsm_asistan_whatsappnumber'); |
| 227 |
|
| 228 |
|
| 229 |
register_setting('netgsmoptions', 'netgsm_asistan_netasistan'); |
| 230 |
register_setting('netgsmoptions', 'netgsm_netasistan_appkey'); |
| 231 |
register_setting('netgsmoptions', 'netgsm_netasistan_userkey'); |
| 232 |
register_setting('netgsmoptions', 'netgsm_netasistan_etiket'); |
| 233 |
|
| 234 |
|
| 235 |
register_setting('netgsmoptions', 'netgsm_netasistan_token'); |
| 236 |
register_setting('netgsmoptions', 'netgsm_netasistan_tokendate'); |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
if (function_exists('wc_get_order_statuses')) { |
| 241 |
$order_statuses = wc_get_order_statuses(); |
| 242 |
$arraykeys = array_keys($order_statuses); |
| 243 |
foreach ($arraykeys as $arraykey) { |
| 244 |
register_setting('netgsmoptions', 'netgsm_order_status_text_' . $arraykey); |
| 245 |
register_setting('netgsmoptions', 'netgsm_order_status_text_' . $arraykey . '_json'); |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
register_setting('netgsmoptions', 'netgsm_cf7_success_customer_control'); |
| 250 |
register_setting('netgsmoptions', 'netgsm_cf7_success_admin_control'); |
| 251 |
register_setting('netgsmoptions', 'netgsm_cf7_contact_control'); |
| 252 |
|
| 253 |
register_setting('netgsmoptions', 'netgsm_cf7_to_admin_no'); |
| 254 |
$cf7_list = apply_filters('netgsm_contact_form_7_list', ''); |
| 255 |
foreach ($cf7_list as $item) { |
| 256 |
register_setting('netgsmoptions', 'netgsm_cf7_list_text_success_customer_' . $item->ID); |
| 257 |
register_setting('netgsmoptions', 'netgsm_cf7_list_text_success_admin_' . $item->ID); |
| 258 |
register_setting('netgsmoptions', 'netgsm_cf7_list_contact_' . $item->ID); |
| 259 |
register_setting('netgsmoptions', 'netgsm_cf7_list_contact_firstname_' . $item->ID); |
| 260 |
register_setting('netgsmoptions', 'netgsm_cf7_list_contact_lastname_' . $item->ID); |
| 261 |
register_setting('netgsmoptions', 'netgsm_cf7_list_contact_other_' . $item->ID); |
| 262 |
register_setting('netgsmoptions', 'netgsm_cf7_list_text_error_' . $item->ID); |
| 263 |
} |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
function netgsm_getCustomSetting($key, $search) |
| 268 |
{ |
| 269 |
$settings = esc_html(get_option($key)); |
| 270 |
if ($settings != '') { |
| 271 |
$jsonData = stripslashes(html_entity_decode($settings)); |
| 272 |
$object = json_decode($jsonData, true); |
| 273 |
if (isset($object[$search])) { |
| 274 |
return $object[$search]; |
| 275 |
} else { |
| 276 |
return ''; |
| 277 |
} |
| 278 |
} |
| 279 |
return $settings; |
| 280 |
} |
| 281 |
|
| 282 |
add_action('admin_footer', 'netgsm_ajaxRequest'); |
| 283 |
|
| 284 |
// Classic checkout (shortcode tabanlı) |
| 285 |
add_action('woocommerce_review_order_before_submit', function () { |
| 286 |
$netgsm_status = get_option('netgsm_status'); |
| 287 |
$iys_checkout_control = get_option('netgsm_iys_checkout_control'); |
| 288 |
if ($netgsm_status != 1 || $iys_checkout_control != 1) { |
| 289 |
return; |
| 290 |
} |
| 291 |
$iys_text = esc_html(get_option('netgsm_iys_checkout_text')); |
| 292 |
$types = type_array(); |
| 293 |
$requires_phone = (in_array('MESAJ', $types) || in_array('ARAMA', $types)) ? 'true' : 'false'; |
| 294 |
$requires_email = in_array('EPOSTA', $types) ? 'true' : 'false'; |
| 295 |
?> |
| 296 |
<div id="netgsm-iys-checkout" style="margin-bottom: 15px;"> |
| 297 |
<p class="form-row"> |
| 298 |
<label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox"> |
| 299 |
<input type="checkbox" name="netgsm_iys_checkout" id="netgsm_iys_checkout" value="1" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" /> |
| 300 |
<span><?php echo $iys_text; ?></span> |
| 301 |
</label> |
| 302 |
</p> |
| 303 |
</div> |
| 304 |
<script> |
| 305 |
(function () { |
| 306 |
var requiresPhone = <?php echo $requires_phone; ?>; |
| 307 |
var requiresEmail = <?php echo $requires_email; ?>; |
| 308 |
|
| 309 |
function setFieldRequired(fieldId, checked) { |
| 310 |
var field = document.getElementById(fieldId); |
| 311 |
if (!field) return; |
| 312 |
field.required = checked; |
| 313 |
|
| 314 |
// Label içindeki .optional span ve .required abbr'yi güncelle |
| 315 |
var wrap = field.closest('.form-row') || field.parentElement; |
| 316 |
if (!wrap) return; |
| 317 |
var label = wrap.querySelector('label'); |
| 318 |
if (!label) return; |
| 319 |
|
| 320 |
var optionalSpan = label.querySelector('.optional'); |
| 321 |
var requiredAbbr = label.querySelector('abbr.required'); |
| 322 |
|
| 323 |
if (checked) { |
| 324 |
if (optionalSpan) optionalSpan.style.display = 'none'; |
| 325 |
if (!requiredAbbr) { |
| 326 |
var abbr = document.createElement('abbr'); |
| 327 |
abbr.className = 'required'; |
| 328 |
abbr.title = 'required'; |
| 329 |
abbr.setAttribute('aria-required', 'true'); |
| 330 |
abbr.textContent = '\u00a0*'; |
| 331 |
abbr.setAttribute('data-netgsm-iys', '1'); |
| 332 |
label.appendChild(abbr); |
| 333 |
} |
| 334 |
} else { |
| 335 |
if (optionalSpan) optionalSpan.style.display = ''; |
| 336 |
if (requiredAbbr && requiredAbbr.getAttribute('data-netgsm-iys')) { |
| 337 |
requiredAbbr.remove(); |
| 338 |
} |
| 339 |
} |
| 340 |
} |
| 341 |
|
| 342 |
function applyIysRequired(checked) { |
| 343 |
if (requiresPhone) setFieldRequired('billing_phone', checked); |
| 344 |
if (requiresEmail) setFieldRequired('billing_email', checked); |
| 345 |
} |
| 346 |
|
| 347 |
function bindCheckbox() { |
| 348 |
var cb = document.getElementById('netgsm_iys_checkout'); |
| 349 |
if (!cb) return; |
| 350 |
cb.addEventListener('change', function () { |
| 351 |
applyIysRequired(this.checked); |
| 352 |
}); |
| 353 |
applyIysRequired(cb.checked); |
| 354 |
} |
| 355 |
|
| 356 |
// İlk yükleme ve WooCommerce updated_checkout sonrası |
| 357 |
document.addEventListener('DOMContentLoaded', bindCheckbox); |
| 358 |
if (typeof jQuery !== 'undefined') { |
| 359 |
jQuery(document.body).on('updated_checkout', bindCheckbox); |
| 360 |
} |
| 361 |
})(); |
| 362 |
</script> |
| 363 |
<?php |
| 364 |
}, 5); |
| 365 |
|
| 366 |
// Classic checkout - sipariş meta kayıt |
| 367 |
add_action('woocommerce_checkout_update_order_meta', function ($order_id) { |
| 368 |
$netgsm_status = get_option('netgsm_status'); |
| 369 |
$iys_checkout_control = get_option('netgsm_iys_checkout_control'); |
| 370 |
if ($netgsm_status != 1 || $iys_checkout_control != 1) { |
| 371 |
return; |
| 372 |
} |
| 373 |
$iys_value = isset($_POST['netgsm_iys_checkout']) ? '1' : '0'; |
| 374 |
update_post_meta($order_id, '_netgsm_iys_checkout', $iys_value); |
| 375 |
if ($iys_value === '1') { |
| 376 |
$order = wc_get_order($order_id); |
| 377 |
$customer_id = $order ? $order->get_customer_id() : 0; |
| 378 |
if ($customer_id > 0) { |
| 379 |
update_user_meta($customer_id, 'netgsm_kvkk_check', '1'); |
| 380 |
} |
| 381 |
netgsm_iys_register_from_order($order); |
| 382 |
} |
| 383 |
}); |
| 384 |
|
| 385 |
// Block checkout - alan kaydı |
| 386 |
add_action('woocommerce_blocks_loaded', function () { |
| 387 |
if (!function_exists('woocommerce_register_additional_checkout_field')) { |
| 388 |
return; |
| 389 |
} |
| 390 |
$netgsm_status = get_option('netgsm_status'); |
| 391 |
$iys_checkout_control = get_option('netgsm_iys_checkout_control'); |
| 392 |
if ($netgsm_status != 1 || $iys_checkout_control != 1) { |
| 393 |
return; |
| 394 |
} |
| 395 |
$iys_text = get_option('netgsm_iys_checkout_text', ''); |
| 396 |
woocommerce_register_additional_checkout_field([ |
| 397 |
'id' => 'netgsm/iys_consent', |
| 398 |
'label' => $iys_text, |
| 399 |
'location' => 'order', |
| 400 |
'type' => 'checkbox', |
| 401 |
'required' => false, |
| 402 |
]); |
| 403 |
}); |
| 404 |
|
| 405 |
// Block checkout - sipariş meta kayıt |
| 406 |
add_action('woocommerce_store_api_checkout_update_order_from_request', function ($order, $request) { |
| 407 |
$netgsm_status = get_option('netgsm_status'); |
| 408 |
$iys_checkout_control = get_option('netgsm_iys_checkout_control'); |
| 409 |
if ($netgsm_status != 1 || $iys_checkout_control != 1) { |
| 410 |
return; |
| 411 |
} |
| 412 |
$additional_fields = $request->get_param('additional_fields') ?? []; |
| 413 |
$iys_value = !empty($additional_fields['netgsm/iys_consent']) ? '1' : '0'; |
| 414 |
$order->update_meta_data('_netgsm_iys_checkout', $iys_value); |
| 415 |
if ($iys_value === '1') { |
| 416 |
$customer_id = $order->get_customer_id(); |
| 417 |
if ($customer_id > 0) { |
| 418 |
update_user_meta($customer_id, 'netgsm_kvkk_check', '1'); |
| 419 |
} |
| 420 |
netgsm_iys_register_from_order($order); |
| 421 |
} |
| 422 |
}, 10, 2); |
| 423 |
|
| 424 |
// Classic checkout - IYS alan doğrulama (tema bağımsız, sunucu taraflı) |
| 425 |
add_action('woocommerce_checkout_process', function () { |
| 426 |
$netgsm_status = get_option('netgsm_status'); |
| 427 |
$iys_checkout_control = get_option('netgsm_iys_checkout_control'); |
| 428 |
if ($netgsm_status != 1 || $iys_checkout_control != 1) { |
| 429 |
return; |
| 430 |
} |
| 431 |
if (empty($_POST['netgsm_iys_checkout']) || $_POST['netgsm_iys_checkout'] != '1') { |
| 432 |
return; |
| 433 |
} |
| 434 |
$types = type_array(); |
| 435 |
if ((in_array('MESAJ', $types) || in_array('ARAMA', $types)) && empty(trim($_POST['billing_phone'] ?? ''))) { |
| 436 |
wc_add_notice('IYS izni için telefon numarası zorunludur.', 'error'); |
| 437 |
} |
| 438 |
if (in_array('EPOSTA', $types) && empty(trim($_POST['billing_email'] ?? ''))) { |
| 439 |
wc_add_notice('IYS izni için e-posta adresi zorunludur.', 'error'); |
| 440 |
} |
| 441 |
}); |
| 442 |
|
| 443 |
// Block checkout - IYS alan doğrulama (tema bağımsız, sunucu taraflı) |
| 444 |
add_action('woocommerce_store_api_checkout_update_order_from_request', function ($order, $request) { |
| 445 |
$netgsm_status = get_option('netgsm_status'); |
| 446 |
$iys_checkout_control = get_option('netgsm_iys_checkout_control'); |
| 447 |
if ($netgsm_status != 1 || $iys_checkout_control != 1) { |
| 448 |
return; |
| 449 |
} |
| 450 |
$additional_fields = $request->get_param('additional_fields') ?? []; |
| 451 |
if (empty($additional_fields['netgsm/iys_consent'])) { |
| 452 |
return; |
| 453 |
} |
| 454 |
$billing = $request->get_param('billing_address') ?? []; |
| 455 |
$types = type_array(); |
| 456 |
$errors = []; |
| 457 |
if ((in_array('MESAJ', $types) || in_array('ARAMA', $types)) && empty(trim($billing['phone'] ?? ''))) { |
| 458 |
$errors[] = 'IYS izni için telefon numarası zorunludur.'; |
| 459 |
} |
| 460 |
if (in_array('EPOSTA', $types) && empty(trim($billing['email'] ?? ''))) { |
| 461 |
$errors[] = 'IYS izni için e-posta adresi zorunludur.'; |
| 462 |
} |
| 463 |
if (!empty($errors)) { |
| 464 |
throw new \Automattic\WooCommerce\StoreApi\Exceptions\RouteException( |
| 465 |
'netgsm_iys_validation', |
| 466 |
implode(' ', $errors), |
| 467 |
400 |
| 468 |
); |
| 469 |
} |
| 470 |
}, 5, 2); |
| 471 |
|
| 472 |
// Ortak IYS kayıt fonksiyonu |
| 473 |
function netgsm_iys_register_from_order($order) { |
| 474 |
if (!$order) return; |
| 475 |
if (get_option('netgsm_brandcode_control') != '1' || get_option('netgsm_brandcode_text') == '') { |
| 476 |
return; |
| 477 |
} |
| 478 |
$billing_phone = $order->get_billing_phone(); |
| 479 |
$billing_email = $order->get_billing_email(); |
| 480 |
if (empty($billing_phone) || empty(type_array())) { |
| 481 |
return; |
| 482 |
} |
| 483 |
$netgsm = new Netgsmsms( |
| 484 |
sanitize_text_field(get_option('netgsm_user')), |
| 485 |
sanitize_text_field(get_option('netgsm_pass')) |
| 486 |
); |
| 487 |
date_default_timezone_set('Europe/Istanbul'); |
| 488 |
$brand_code = sanitize_text_field(get_option('netgsm_brandcode_text')); |
| 489 |
$recipient_type_option = sanitize_text_field(get_option('netgsm_recipient_type')); |
| 490 |
$recipient_type = ($recipient_type_option == '2') ? 'TACIR' : 'BIREYSEL'; |
| 491 |
$netgsm->iysadd(iys_phonecontrol($billing_phone), $billing_email, date('Y-m-d H:i:s'), $brand_code, $recipient_type, type_array()); |
| 492 |
} |
| 493 |
function netgsm_ajaxRequest() |
| 494 |
{ ?> |
| 495 |
<script type="text/javascript"> |
| 496 |
function privatesmsSend(number = "") { |
| 497 |
var phone = document.getElementById('private_phone').value; |
| 498 |
var message = document.getElementById('private_text').value; |
| 499 |
var content_type = document.getElementById('netgsm_content_type').value; |
| 500 |
var filter = content_type; |
| 501 |
|
| 502 |
if (phone == "" || message == "" || content_type == "") { |
| 503 |
swal('Mesaj göndermek için lütfen gerekli alanları doldurun.'); |
| 504 |
return; |
| 505 |
} |
| 506 |
document.getElementById('sendSMS').disabled = true; |
| 507 |
var data = { |
| 508 |
'action': 'netgsm_sendsms', |
| 509 |
'phone': phone, |
| 510 |
'message': message, |
| 511 |
'filter': filter, |
| 512 |
'_wpnonce': "<?php echo esc_attr( wp_create_nonce( 'netgsm_sendsms' ) ); ?>" |
| 513 |
}; |
| 514 |
|
| 515 |
jQuery.post(ajaxurl, data, function(response) { |
| 516 |
|
| 517 |
|
| 518 |
var obje = JSON.parse(response); |
| 519 |
if (obje.durum == 1) { |
| 520 |
document.getElementById('private_phone').value = ""; |
| 521 |
document.getElementById('private_text').value = ""; |
| 522 |
swal({ |
| 523 |
title: "BAŞARILI!", |
| 524 |
html: obje.mesaj + '<br><br><b>' + phone + '</b> numarasına ' + '"<b>' + sanitizeTextField(message) + '</b>" gönderildi.', |
| 525 |
type: 'success' |
| 526 |
}); |
| 527 |
} else { |
| 528 |
swal({ |
| 529 |
title: "HATA! Kod : " + obje.kod, |
| 530 |
text: obje.mesaj, |
| 531 |
type: 'error' |
| 532 |
}); |
| 533 |
} |
| 534 |
document.getElementById('sendSMS').disabled = false; |
| 535 |
}); |
| 536 |
} |
| 537 |
|
| 538 |
function sanitizeTextField(str) { |
| 539 |
// 1. Backslash temizle |
| 540 |
str = str.replace(/\\/g, ''); |
| 541 |
// 2. HTML tag'lerini sil |
| 542 |
str = str.replace(/<[^>]*>?/gm, ''); |
| 543 |
// 3. Trim (baş ve sondaki boşluklar) |
| 544 |
str = str.trim(); |
| 545 |
return str; |
| 546 |
} |
| 547 |
function netgsm_sendSMS_bulkTab(id = "",$phone=0) { |
| 548 |
var bulkBtn = document.getElementById('bulkSMSbtn'); |
| 549 |
if (bulkBtn) bulkBtn.disabled = true; |
| 550 |
var users = []; |
| 551 |
var numberstext; |
| 552 |
if (id != "") { |
| 553 |
users = id; |
| 554 |
numberstext = "numarasına"; |
| 555 |
} else { |
| 556 |
var table = jQuery('#table'); |
| 557 |
var sonuc = table.bootstrapTable('getAllSelections'); |
| 558 |
for (var i = 0; i < sonuc.length; i++) { |
| 559 |
users += sonuc[i].userid + ","; |
| 560 |
} |
| 561 |
numberstext = "numaralarına"; |
| 562 |
} |
| 563 |
if($phone!=0 && $phone != "" ){ |
| 564 |
numberstext=$phone |
| 565 |
} |
| 566 |
var mark = '<mark class="bulkmark" onclick="varfill2(this.innerHTML);">'; |
| 567 |
var variables = mark + '[uye_adi]</mark>  ' + mark + '[uye_soyadi]</mark>  ' + mark + '[uye_telefonu]</mark>  ' + mark + '[uye_epostasi]</mark>  ' + mark + '[kullanici_adi]</mark> ' + mark + '[tarih]</mark> ' + mark + '[saat]</mark>'; |
| 568 |
if (users != "") { |
| 569 |
|
| 570 |
swal({ |
| 571 |
title: "Mesaj", |
| 572 |
input: 'textarea', |
| 573 |
inputPlaceholder: 'Mesaj İçeriğini buraya giriniz.', |
| 574 |
html: '<select id="swal-input2" name="swal-input2" class="swal2-select" style="border-color: #d9d9d9 " >' + |
| 575 |
'<option style="color: #2c3338" value=""> Mesaj içerik türü seçiniz</option>' + |
| 576 |
'<option style="color: #2c3338" value="11"> Kampanya, tanıtım, kutlama vb. (İYS\'ye bireysel kayıtlı alıcılarınıza gönderilir.) </option>' + |
| 577 |
'<option style="color: #2c3338" value="12"> Kampanya, tanıtım, kutlama vb. (İYS\'ye tacir kayıtlı alıcılarınıza gönderilir.) </option>' + |
| 578 |
'<option style="color: #2c3338" value="0"> Bilgilendirme, kargo, şifre vb. (İYS\'den sorgulanmaz.)</option>' + |
| 579 |
'</select>' + |
| 580 |
'<i style="font-size: small; color: #555">*Tanımlı marka kodunuz bulunmuyorsa Bilgilendirme, kargo, şifre vb. (İYS\'den sorgulanmaz.) seçilmelidir.</i>', |
| 581 |
confirmButtonText: 'Gönder', |
| 582 |
cancelButtonText: 'İptal', |
| 583 |
confirmButtonColor: '#2ECC71', |
| 584 |
cancelButtonColor: '#E74C3C', |
| 585 |
width: 650, |
| 586 |
showCancelButton: true, |
| 587 |
showLoaderOnConfirm: true, |
| 588 |
footer: '<i class="fa fa-angle-double-right"></i> Kullanabileceğiniz Değişkenler : ' + variables, |
| 589 |
preConfirm: function(text) { |
| 590 |
return new Promise(function(resolve, reject) { |
| 591 |
if (text) { |
| 592 |
var message = text; |
| 593 |
var content_type = document.getElementById('swal-input2').value; |
| 594 |
var filter = content_type; |
| 595 |
if (content_type == '') { |
| 596 |
resolve(); |
| 597 |
swal({ |
| 598 |
title: "Mesaj içerik türü seçilmedi.", |
| 599 |
text: "Lütfen sms göndermek için mesaj içerik türü seçiniz.", |
| 600 |
type: 'error', |
| 601 |
}); |
| 602 |
} else { |
| 603 |
var data = { |
| 604 |
'action': 'netgsm_sendSMS_bulkTab', |
| 605 |
'users': users, |
| 606 |
'message': message, |
| 607 |
'sendPhone' : numberstext, |
| 608 |
'filter': filter, |
| 609 |
'_wpnonce': "<?php echo esc_attr( wp_create_nonce( 'netgsm_sendSMS_bulkTab' ) ); ?>" |
| 610 |
}; |
| 611 |
jQuery.post(ajaxurl, data, function(response) { |
| 612 |
var obje = JSON.parse(response); |
| 613 |
resolve(); |
| 614 |
if (obje.durum == 1) { |
| 615 |
swal({ |
| 616 |
title: "BAŞARILI!", |
| 617 |
html: obje.mesaj + '<br><br><b>' + obje.phones + '</b> ' + numberstext + ' "<b>' + sanitizeTextField(message) + '</b>" gönderildi.', |
| 618 |
type: 'success' |
| 619 |
}); |
| 620 |
} else { |
| 621 |
swal({ |
| 622 |
title: "HATA! Kod : " + obje.kod, |
| 623 |
text: obje.mesaj, |
| 624 |
type: 'error' |
| 625 |
}); |
| 626 |
} |
| 627 |
if (bulkBtn) bulkBtn.disabled = false; |
| 628 |
}); |
| 629 |
} |
| 630 |
} else { |
| 631 |
resolve(); |
| 632 |
swal({ |
| 633 |
title: "Mesaj içeriğini boş bıraktınız.", |
| 634 |
text: "Lütfen sms göndermek için birşeyler yazın.", |
| 635 |
type: 'error', |
| 636 |
}); |
| 637 |
if (bulkBtn) bulkBtn.disabled = false; |
| 638 |
} |
| 639 |
document.getElementById('bulkSMSbtn').disabled = false; |
| 640 |
}) |
| 641 |
} |
| 642 |
}).then(function() { |
| 643 |
if (bulkBtn) bulkBtn.disabled = false; |
| 644 |
}); |
| 645 |
} else { |
| 646 |
if (bulkBtn) bulkBtn.disabled = false; |
| 647 |
swal('Mesaj göndermek için müşteri seçmelisiniz.'); |
| 648 |
return; |
| 649 |
} |
| 650 |
} |
| 651 |
|
| 652 |
function sendSMSglobal(phone) { |
| 653 |
if (!jQuery.isNumeric(phone)) { |
| 654 |
swal({ |
| 655 |
title: "Uyarı!", |
| 656 |
text: 'Sadece telefon numaralarına SMS gönderilebilir.', |
| 657 |
type: 'error' |
| 658 |
}); |
| 659 |
return false; |
| 660 |
|
| 661 |
} |
| 662 |
if (phone != "") { |
| 663 |
swal({ |
| 664 |
title: "Mesaj", |
| 665 |
input: 'textarea', |
| 666 |
inputPlaceholder: 'Mesaj İçeriğini buraya giriniz.', |
| 667 |
confirmButtonText: 'Gönder', |
| 668 |
cancelButtonText: 'İptal', |
| 669 |
confirmButtonColor: '#2ECC71', |
| 670 |
cancelButtonColor: '#E74C3C', |
| 671 |
width: 650, |
| 672 |
showCancelButton: true, |
| 673 |
showLoaderOnConfirm: true, |
| 674 |
footer: 'Kayıtlı olmayan bir numaraya sms atıyorsunuz.', |
| 675 |
preConfirm: function(text) { |
| 676 |
return new Promise(function(resolve, reject) { |
| 677 |
if (text) { |
| 678 |
var message = text; |
| 679 |
var data = { |
| 680 |
'action': 'netgsm_sendsms', |
| 681 |
'phone': phone, |
| 682 |
'message': message, |
| 683 |
'_wpnonce': "<?php echo esc_attr( wp_create_nonce( 'netgsm_sendsms' ) ); ?>" |
| 684 |
}; |
| 685 |
jQuery.post(ajaxurl, data, function(response) { |
| 686 |
var obje = JSON.parse(response); |
| 687 |
resolve(); |
| 688 |
if (obje.durum == 1) { |
| 689 |
swal({ |
| 690 |
title: "BAŞARILI!", |
| 691 |
html: obje.mesaj + '<br><br><b>' + phone + '</b> numarasına ' + '"<b>' + sanitizeTextField(message) + '</b>" gönderildi.', |
| 692 |
type: 'success' |
| 693 |
}); |
| 694 |
} else { |
| 695 |
swal({ |
| 696 |
title: "HATA! Kod : " + obje.kod, |
| 697 |
text: obje.mesaj, |
| 698 |
type: 'error' |
| 699 |
}); |
| 700 |
} |
| 701 |
}); |
| 702 |
} else { |
| 703 |
resolve(); |
| 704 |
swal({ |
| 705 |
title: "Mesaj içeriğini boş bıraktınız.", |
| 706 |
text: "Lütfen sms göndermek için birşeyler yazın.", |
| 707 |
type: 'error', |
| 708 |
}); |
| 709 |
} |
| 710 |
}) |
| 711 |
} |
| 712 |
}) |
| 713 |
} else { |
| 714 |
swal('Mesaj göndermek için müşteri seçmelisiniz.'); |
| 715 |
return; |
| 716 |
} |
| 717 |
} |
| 718 |
|
| 719 |
function varfill2(degisken) { |
| 720 |
var textarea = document.getElementsByClassName('swal2-textarea')[0]; |
| 721 |
var start = textarea.selectionStart; |
| 722 |
var end = textarea.selectionEnd; |
| 723 |
var finText = textarea.value.substring(0, start) + degisken + textarea.value.substring(end); |
| 724 |
textarea.value = finText; |
| 725 |
textarea.focus(); |
| 726 |
textarea.selectionEnd = end + (degisken.length); |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
var xhr = ''; |
| 732 |
var m = 0; |
| 733 |
var errorControl = 0; |
| 734 |
jQuery('a[data-toggle="tab"]').on('shown.bs.tab', function(e) { |
| 735 |
var target = jQuery(e.target).attr("href") // activated tab |
| 736 |
if (target == '#voip') { |
| 737 |
var type = 'netsantral'; |
| 738 |
var date = new Date(); |
| 739 |
if (m == 0 || date.getMinutes() - m > 2) { |
| 740 |
showLoadingMessage('Görüşme kayıtları getiriliyor...'); |
| 741 |
var data = { |
| 742 |
'action': 'netgsm_getNetsantral_Report', |
| 743 |
'type': type, |
| 744 |
'_wpnonce': "<?php echo esc_attr( wp_create_nonce( 'netgsm_getNetsantral_Report' ) ); ?>" |
| 745 |
}; |
| 746 |
xhr = jQuery.post(ajaxurl, data, function(response) { |
| 747 |
var response = JSON.parse(response); |
| 748 |
if (response["status"] == 'success') { |
| 749 |
jQuery('#santralTable').html(response["message"]); |
| 750 |
jQuery('#santralTab').html(response["type"]); |
| 751 |
jQuery('#santralInfo').html(response["info"] + ' <i class="fa fa-info-circle" data-toggle="tooltip" data-placement="left" title="Maximum 250 kayıt gösterilir. Daha fazla görüntülemek için Netgsm Webportal\'ı ziyaret edin."></i>'); |
| 752 |
m = date.getMinutes(); |
| 753 |
} else { |
| 754 |
m = 0; |
| 755 |
swal({ |
| 756 |
title: "Başarısız", |
| 757 |
text: response['info'], |
| 758 |
type: 'error' |
| 759 |
}); |
| 760 |
jQuery('#santralInfo').html(response["info"] + ' Lütfen daha sonra tekrar deneyin.'); |
| 761 |
} |
| 762 |
jQuery('[data-toggle="tooltip"]').tooltip(); |
| 763 |
hideLoadingMessage(); |
| 764 |
}); |
| 765 |
} |
| 766 |
} |
| 767 |
}); |
| 768 |
|
| 769 |
jQuery(document).keyup(function(e) { |
| 770 |
if (e.keyCode == 27) { |
| 771 |
hideLoadingMessage(); |
| 772 |
errorControl = 1; |
| 773 |
xhr.abort(); |
| 774 |
} |
| 775 |
}); |
| 776 |
</script> |
| 777 |
<?php |
| 778 |
} |
| 779 |
|
| 780 |
add_action('woocommerce_single_product_summary', 'stokta_yoksa_sms_formu_goster', 20); |
| 781 |
function stokta_yoksa_sms_formu_goster() { |
| 782 |
global $product; |
| 783 |
if (!$product->is_in_stock() && get_option('netgsm_product_waitlist1_control') == 1) { |
| 784 |
$current_user = wp_get_current_user(); |
| 785 |
$showPhoneInput=true; |
| 786 |
if($current_user && $current_user->id != 0){ |
| 787 |
$billing_phone = get_user_meta($current_user->id, 'billing_phone', true); |
| 788 |
if($billing_phone){ |
| 789 |
$showPhoneInput=false; |
| 790 |
} |
| 791 |
} |
| 792 |
|
| 793 |
// Başarı/başarısız mesaj |
| 794 |
if (isset($_GET['sms_status'])) { |
| 795 |
if ($_GET['sms_status'] === 'ok') { |
| 796 |
echo '<div style="color: green;">Kayıt başarılı! Teşekkürler.</div>'; |
| 797 |
} elseif ($_GET['sms_status'] === 'exists') { |
| 798 |
echo '<div style="color: orange;">Bu telefon numarası ile zaten kayıt yapılmış.</div>'; |
| 799 |
} elseif ($_GET['sms_status'] === 'fail') { |
| 800 |
echo '<div style="color: red;">Bir hata oluştu. Lütfen tekrar deneyin.</div>'; |
| 801 |
} |
| 802 |
} |
| 803 |
?> |
| 804 |
<div id="stok_sms_form" style="max-width: 400px; font-family: Arial, sans-serif;"> |
| 805 |
<h4 style="text-align: center; margin-bottom: 20px;">Stok geldiğinde haber ver!</h4> |
| 806 |
<form method="post"> |
| 807 |
<input |
| 808 |
type="text" |
| 809 |
name="sms_name" |
| 810 |
placeholder="Adınız" |
| 811 |
required |
| 812 |
style="width: 100%; padding: 8px 10px; margin-bottom: 12px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box;" |
| 813 |
/> |
| 814 |
<input |
| 815 |
type="email" |
| 816 |
name="sms_email" |
| 817 |
placeholder="E-posta" |
| 818 |
required |
| 819 |
style="width: 100%; padding: 8px 10px; margin-bottom: 12px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box;" |
| 820 |
/> |
| 821 |
<?php if ( $showPhoneInput ) : ?> |
| 822 |
<input |
| 823 |
type="tel" |
| 824 |
name="sms_phone" |
| 825 |
placeholder="Telefon (5xx...)" |
| 826 |
required |
| 827 |
style="width: 100%; padding: 8px 10px; margin-bottom: 15px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box;" |
| 828 |
/> |
| 829 |
<?php endif; ?> |
| 830 |
<input type="hidden" name="product_id" value="<?php echo $product->get_id(); ?>" /> |
| 831 |
<button |
| 832 |
type="submit" |
| 833 |
name="sms_notify_submit" |
| 834 |
style="width: 100%; padding: 10px; background-color: #0073aa; color: white; border: none; border-radius: 4px; font-size: 16px; cursor: pointer;" |
| 835 |
> |
| 836 |
Kaydet |
| 837 |
</button> |
| 838 |
</form> |
| 839 |
</div> |
| 840 |
|
| 841 |
|
| 842 |
<?php |
| 843 |
} |
| 844 |
} |
| 845 |
// stok yok ise bu arayuzde acılan formdan gelen bilgiler db ye kaydediliyor ve sms stok geldiginde sms gonderecez |
| 846 |
add_action('init', 'save_stock_sms_form_data'); |
| 847 |
function save_stock_sms_form_data() { |
| 848 |
if (isset($_POST['sms_notify_submit'])) { |
| 849 |
global $wpdb; |
| 850 |
$current_user_id = get_current_user_id(); // 0 ise giriş yapılmamış demektir |
| 851 |
$name = sanitize_text_field($_POST['sms_name']); |
| 852 |
$email = sanitize_email($_POST['sms_email']); |
| 853 |
$phone = sanitize_text_field($_POST['sms_phone']); |
| 854 |
$product_id = intval($_POST['product_id']); |
| 855 |
|
| 856 |
$table_name = $wpdb->prefix . 'sms_notifications'; |
| 857 |
// Daha önce kayıt var mı kontrolü |
| 858 |
$exists = $wpdb->get_var($wpdb->prepare( |
| 859 |
"SELECT COUNT(*) FROM $table_name WHERE phone = %s AND product_id = %d AND notified = 0", |
| 860 |
$phone, |
| 861 |
$product_id |
| 862 |
)); |
| 863 |
$product_url = get_permalink($product_id); |
| 864 |
if ($exists > 0) { |
| 865 |
wp_redirect( add_query_arg('sms_status', 'exists', $product_url) ); |
| 866 |
exit; |
| 867 |
} |
| 868 |
|
| 869 |
$result = $wpdb->insert($table_name, [ |
| 870 |
'user_name' => $name, |
| 871 |
'email' => $email, |
| 872 |
'phone' => $phone, |
| 873 |
'product_id' => $product_id, |
| 874 |
'customer_id' => $current_user_id, |
| 875 |
'notified' => 0, |
| 876 |
]); |
| 877 |
if ($result === false) { |
| 878 |
error_log('Table name: ' . $wpdb->prefix . 'sms_notifications insert basarisiz urunid:'.$product_id.'-'.$_POST['sms_email'].'-' . $_POST['sms_phone']); |
| 879 |
} |
| 880 |
|
| 881 |
if ($result !== false) { |
| 882 |
wp_redirect(add_query_arg('sms_status', 'ok', $product_url)); |
| 883 |
} else { |
| 884 |
wp_redirect(add_query_arg('sms_status', 'error', $product_url)); |
| 885 |
} |
| 886 |
exit; |
| 887 |
} |
| 888 |
|
| 889 |
} |
| 890 |
|
| 891 |
|
| 892 |
// stoga urunlere geldi ise urun geldiginde haber ver diyen kullancılara sms gonderiyouz |
| 893 |
add_action('woocommerce_product_set_stock_status', 'send_sms_when_back_in_stock', 10, 3); |
| 894 |
function send_sms_when_back_in_stock($product_id, $stock_status, $product) { |
| 895 |
// Güvenlik kontrolü: ürün nesnesi geçerli mi? |
| 896 |
if (!$product instanceof WC_Product) { |
| 897 |
return; |
| 898 |
} |
| 899 |
// Yeni stok durumu "instock" VE daha önceki durum "outofstock" ise SMS gönder |
| 900 |
if ($stock_status === 'instock') { |
| 901 |
|
| 902 |
$control = esc_html(get_option("netgsm_product_waitlist1_control")); |
| 903 |
$message = trim(esc_html(get_option("netgsm_product_waitlist1_text"))); |
| 904 |
$netgsm_status = esc_html(get_option("netgsm_status")); |
| 905 |
|
| 906 |
if (!empty($netgsm_status) && $netgsm_status == 1 && !empty($control) && $control == 1 && !empty($message)) { |
| 907 |
|
| 908 |
global $wpdb; |
| 909 |
$table = $wpdb->prefix . 'sms_notifications'; |
| 910 |
$customerNotifications = $wpdb->get_results("SELECT * FROM $table WHERE product_id = $product_id AND notified = 0"); |
| 911 |
$tarih = date('d.m.Y'); |
| 912 |
$saat = date('H:i:s'); |
| 913 |
$bulkBody = ""; |
| 914 |
$product_link = get_permalink($product_id); |
| 915 |
$message = sanitize_textarea_field(wp_unslash($message)); |
| 916 |
$message = strip_tags($message); |
| 917 |
foreach ($customerNotifications as $customerNotification) { |
| 918 |
|
| 919 |
if($customerNotification->customer_id){ |
| 920 |
$customer = new WC_Customer($customerNotification->customer_id); |
| 921 |
} |
| 922 |
|
| 923 |
$data = array( |
| 924 |
'first_name' => $customerNotification->user_name, |
| 925 |
'last_name' => "", |
| 926 |
'phone' => $customerNotification->phone, |
| 927 |
'user_email' => $customerNotification->email, |
| 928 |
'kullanici_adi' => $customerNotification->user_name, |
| 929 |
'urun_adi' => $product->get_name(), |
| 930 |
'tarih' => $tarih, |
| 931 |
'saat' => $saat, |
| 932 |
'urun_bilgileri' => $product_link, |
| 933 |
'message' => $message |
| 934 |
); |
| 935 |
|
| 936 |
if($customer){ |
| 937 |
$data['first_name']= $customer->get_first_name(); |
| 938 |
$data['last_name']= $customer->get_last_name(); |
| 939 |
$data['phone']= $customer->get_billing_phone() =="" ? $customerNotification->phone : $customer->get_billing_phone(); |
| 940 |
$data['user_email']= $customer->get_email(); |
| 941 |
$data['kullanici_adi']= $customer->get_username(); |
| 942 |
$data['urun_kodu']= $customer->sku; |
| 943 |
$data['stok_miktari']= $customer->stock_quantity; |
| 944 |
} |
| 945 |
$replace = new ReplaceFunction(); |
| 946 |
$messageText = $replace->netgsm_replace_stock_bulksms($data); |
| 947 |
$bulkBody .= '<mp><msg><![CDATA[' . $messageText . ']]></msg><no>' . $data['phone'] . '</no></mp>'; |
| 948 |
$customer=null; |
| 949 |
} |
| 950 |
|
| 951 |
if ($bulkBody =="") { |
| 952 |
return; |
| 953 |
} |
| 954 |
$netgsm = new Netgsmsms(sanitize_text_field(get_option("netgsm_user")), sanitize_text_field(get_option("netgsm_pass")), sanitize_text_field(get_option('netgsm_input_smstitle')), sanitize_text_field(get_option("netgsm_trChar"))); |
| 955 |
$json = $netgsm->sendBulkSMS($bulkBody); |
| 956 |
if (array_key_exists('gorevid', $json)) { |
| 957 |
// sms gonderildi olarak guncelle |
| 958 |
$wpdb->update($table, ['notified' => 1], ['product_id' => $product_id]); |
| 959 |
|
| 960 |
} |
| 961 |
|
| 962 |
} |
| 963 |
} |
| 964 |
} |
| 965 |
|
| 966 |
|
| 967 |
add_action('wp_ajax_netgsm_getNetsantral_Report', 'netgsm_getNetsantral_Report'); |
| 968 |
function netgsm_getNetsantral_Report() |
| 969 |
{ |
| 970 |
if ( ! wp_verify_nonce( $_POST['_wpnonce'], 'netgsm_getNetsantral_Report' ) ) { |
| 971 |
wp_die(); |
| 972 |
} |
| 973 |
$json = array(); |
| 974 |
$netgsm = new Netgsmsms(sanitize_text_field(get_option("netgsm_user")), sanitize_text_field(get_option("netgsm_pass")), sanitize_text_field(get_option('netgsm_input_smstitle')), sanitize_text_field(get_option("netgsm_trChar"))); |
| 975 |
$json = $netgsm->getVoipReport(); |
| 976 |
$type = 'NETSANTRAL'; |
| 977 |
$info = ''; |
| 978 |
$table = '<table data-pagination="true" id="table_voip" name="table_voip" class="table table-bordered table-striped dataTable no-footer" |
| 979 |
data-search="true" data-search-align="left" |
| 980 |
data-pagination-v-align="bottom" |
| 981 |
data-click-to-select="true" |
| 982 |
data-toggle="table" |
| 983 |
data-page-list="[10, 25, 50, 100, 150, 200]"> <thead><th>#</th><th>Tarih</th><th>Arayan</th><th>Aranan</th><th>Süre</th><th>Yön</th><th>İşlemler</th></thead><tbody>'; |
| 984 |
|
| 985 |
$object = json_decode($json); |
| 986 |
if (is_object($object) && isset($object->success)) { |
| 987 |
// Tüm kullanıcıları belleğe almak yerine yalnızca rapordaki |
| 988 |
// numaraları tek sorguda kullanıcılara eşle. |
| 989 |
$phoneMap = $netgsm->phonesToUserMap(wp_list_pluck($object->data, 'caller_number')); |
| 990 |
foreach ($object->data as $key => $data) { |
| 991 |
if ($key >= 250) { |
| 992 |
break; |
| 993 |
} |
| 994 |
$table .= '<tr>'; |
| 995 |
$table .= '<td><a href="https://www.netgsm.com.tr/webportal/netsantral/cdr/gorusme_detayi/' . $data->call_id . '" target="_blank">' . $data->call_id . '</a></td>'; |
| 996 |
$table .= '<td>' . $data->date . '</td>'; |
| 997 |
|
| 998 |
$customer = $phoneMap[ltrim($data->caller_number, '0')] ?? null; |
| 999 |
//echo json_encode(['status'=>'success', 'message'=>$customer, 'type'=>$type, 'info'=>$info]); |
| 1000 |
//wp_die(); |
| 1001 |
$c_id = 0; |
| 1002 |
$c_name = ''; |
| 1003 |
if ($customer != null) { |
| 1004 |
$c_id = $customer->ID; |
| 1005 |
if (isset($customer->first_name) && $customer->first_name != '') { |
| 1006 |
$c_name = $customer->first_name . ' ' . $customer->last_name; |
| 1007 |
} else { |
| 1008 |
$c_name = $customer->user_login; |
| 1009 |
} |
| 1010 |
} |
| 1011 |
|
| 1012 |
if ($c_name == ' ' || $c_name == '') { |
| 1013 |
$table .= '<td class="username column-username has-row-actions column-primary" data-colname="Kullanıcı adı"> |
| 1014 |
<img alt="" src="http://1.gravatar.com/avatar/af6a28e91103e7157c9451d7b754efd2?s=32&d=mm&r=g" srcset="http://1.gravatar.com/avatar/af6a28e91103e7157c9451d7b754efd2?s=64&d=mm&r=g 2x" class="avatar avatar-32 photo" height="32" width="32" data-toggle="tooltip" data-placement="top" title="Kayıtlı değil"><span data-toggle="tooltip" data-placement="top" title="Kayıtlı değil">' . $data->caller_number . '</span></td>'; |
| 1015 |
} else { |
| 1016 |
$table .= '<td class="username column-username has-row-actions column-primary" data-colname="Kullanıcı adı"> |
| 1017 |
<img alt="" src="http://1.gravatar.com/avatar/af6a28e91103e7157c9451d7b754efd2?s=32&d=mm&r=g" srcset="http://1.gravatar.com/avatar/af6a28e91103e7157c9451d7b754efd2?s=64&d=mm&r=g 2x" class="avatar avatar-32 photo" height="32" width="32" data-toggle="tooltip" data-placement="top" title="' . $c_name . '"> |
| 1018 |
<a href="user-edit.php?user_id=' . $c_id . '" target="_blank" data-toggle="tooltip" data-placement="top" title="' . $data->caller_number . '">' . $c_name . '</a></td>'; |
| 1019 |
} |
| 1020 |
|
| 1021 |
$table .= '<td>' . $data->dial_number . '</td>'; |
| 1022 |
$table .= '<td>' . $netgsm->timeconvert($data->time) . '</td>'; |
| 1023 |
|
| 1024 |
$direction = ''; |
| 1025 |
switch ($data->direction) { |
| 1026 |
case 0: //giden |
| 1027 |
$direction = '<i class="fa fa-arrow-circle-o-up" style="color: #3498DB;"></i> Giden'; |
| 1028 |
break; |
| 1029 |
case 1: |
| 1030 |
$direction = '<i class="fa fa-arrow-circle-down" style="color: #2ECC71;"></i> Gelen'; |
| 1031 |
break; |
| 1032 |
case 2: |
| 1033 |
$direction = '<i class="fa fa-arrow-circle-down" style="color: #E74C3C;"></i> Gelen Cevapsız'; |
| 1034 |
break; |
| 1035 |
case 3: |
| 1036 |
$direction = '<i class="fa fa-arrow-circle-up" style="color: #E74C3C;"></i> Giden Cevapsız'; |
| 1037 |
break; |
| 1038 |
case 4: |
| 1039 |
break; |
| 1040 |
$direction = '<i class="fa fa-arrow-circle-left" style="color: #2C3E50;"></i> <i class="fa fa-arrow-circle-right" style="color: #2C3E50;"></i> İç Arama'; |
| 1041 |
case 5: |
| 1042 |
break; |
| 1043 |
$direction = '<i class="fa fa-arrow-circle-left" style="color: #E74C3C;"></i> <i class="fa fa-arrow-circle-right" style="color: #E74C3C;"></i> İç Cevapsız Arama'; |
| 1044 |
default: |
| 1045 |
$direction = 'Bilinmiyor'; |
| 1046 |
break; |
| 1047 |
} |
| 1048 |
$table .= '<td>' . $direction . '</td>'; |
| 1049 |
if (strlen($data->caller_number) == 11) { |
| 1050 |
if ($c_id != '') { |
| 1051 |
$table .= '<td><a href="javascript:void(0);" class="btn btn-info btn-sm" onclick="netgsm_sendSMS_bulkTab(\'' . $c_id . '\',\'' . $data->caller_number . '\'); ">Arayana SMS Gönder</a></td>'; |
| 1052 |
} else { |
| 1053 |
$table .= '<td><a href="javascript:void(0);" class="btn btn-info btn-sm" onclick="sendSMSglobal(\'' . $data->caller_number . '\'); ">Arayana SMS Gönder</a></td>'; |
| 1054 |
} |
| 1055 |
} else { |
| 1056 |
$table .= '<td></td>'; |
| 1057 |
} |
| 1058 |
$table .= '</tr>'; |
| 1059 |
} |
| 1060 |
$table .= '</tbody></table>'; |
| 1061 |
$message = $table; |
| 1062 |
$status = 'success'; |
| 1063 |
$type = 'NETSANTRAL'; |
| 1064 |
$info = $object->success->message; |
| 1065 |
} else { |
| 1066 |
if (is_object($object) && isset($object->error)) { |
| 1067 |
if (in_array($object->error->code, [30, 80])) { |
| 1068 |
$json = $netgsm->getPhoneReport(); |
| 1069 |
|
| 1070 |
$table = '<table data-pagination="true" id="table" name="table" class="table table-bordered table-striped dataTable no-footer" |
| 1071 |
data-search="true" data-search-align="left" |
| 1072 |
data-pagination-v-align="bottom" |
| 1073 |
data-click-to-select="true" |
| 1074 |
data-toggle="table" |
| 1075 |
data-page-list="[10, 25, 50, 100, 150, 200]"><thead><th>#</th><th>Tarih</th><th>Arayan</th><th>Süre</th><th>Yön</th><th>İşlemler</th></thead><tbody>'; |
| 1076 |
$object = json_decode($json); |
| 1077 |
if (is_object($object) && isset($object->success)) { |
| 1078 |
$phoneMap = $netgsm->phonesToUserMap(wp_list_pluck($object->data, 'caller_number')); |
| 1079 |
foreach ($object->data as $key => $data) { |
| 1080 |
if ($key >= 250) { |
| 1081 |
break; |
| 1082 |
} |
| 1083 |
$table .= '<tr>'; |
| 1084 |
$table .= '<td>#</td>'; |
| 1085 |
$table .= '<td>' . $data->date . '</td>'; |
| 1086 |
|
| 1087 |
$customer = $phoneMap[ltrim($data->caller_number, '0')] ?? null; |
| 1088 |
$c_id = 0; |
| 1089 |
$c_name = ''; |
| 1090 |
if ($customer != null) { |
| 1091 |
$c_id = $customer->ID; |
| 1092 |
if (isset($customer->first_name) && $customer->first_name != '') { |
| 1093 |
$c_name = $customer->first_name . ' ' . $customer->last_name; |
| 1094 |
} else { |
| 1095 |
$c_name = $customer->user_login; |
| 1096 |
} |
| 1097 |
} |
| 1098 |
|
| 1099 |
if ($c_name == ' ' || $c_name == '') { |
| 1100 |
$table .= '<td class="username column-username has-row-actions column-primary" data-colname="Kullanıcı adı"> |
| 1101 |
<img alt="" src="https://1.gravatar.com/avatar/af6a28e91103e7157c9451d7b754efd2?s=32&d=mm&r=g" srcset="https://1.gravatar.com/avatar/af6a28e91103e7157c9451d7b754efd2?s=64&d=mm&r=g 2x" class="avatar avatar-32 photo" height="32" width="32" data-toggle="tooltip" data-placement="top" title="Kayıtlı değil"><span data-toggle="tooltip" data-placement="top" title="Kayıtlı değil">' . $data->caller_number . '</span></td>'; |
| 1102 |
} else { |
| 1103 |
$table .= '<td class="username column-username has-row-actions column-primary" data-colname="Kullanıcı adı"> |
| 1104 |
<img alt="" src="https://1.gravatar.com/avatar/af6a28e91103e7157c9451d7b754efd2?s=32&d=mm&r=g" srcset="https://1.gravatar.com/avatar/af6a28e91103e7157c9451d7b754efd2?s=64&d=mm&r=g 2x" class="avatar avatar-32 photo" height="32" width="32" data-toggle="tooltip" data-placement="top" title="' . $c_name . '"> |
| 1105 |
<a href="user-edit.php?user_id=' . $c_id . '" target="_blank" data-toggle="tooltip" data-placement="top" title="' . $data->caller_number . '">' . $c_name . '</a></td>'; |
| 1106 |
} |
| 1107 |
|
| 1108 |
$table .= '<td>' . $netgsm->timeconvert($data->time) . '</td>'; |
| 1109 |
|
| 1110 |
$direction = ''; |
| 1111 |
switch ($data->direction) { |
| 1112 |
case 1: |
| 1113 |
$direction = '<i class="fa fa-arrow-circle-down" style="color: #2ECC71;"></i> Gelen'; |
| 1114 |
break; |
| 1115 |
case 2: //giden |
| 1116 |
$direction = '<i class="fa fa-arrow-circle-o-up" style="color: #3498DB;"></i> Giden'; |
| 1117 |
break; |
| 1118 |
case 3: |
| 1119 |
$direction = '<i class="fa fa-arrow-circle-down" style="color: #E74C3C;"></i> Cevapsız'; |
| 1120 |
break; |
| 1121 |
default: |
| 1122 |
$direction = 'Bilinmiyor'; |
| 1123 |
break; |
| 1124 |
} |
| 1125 |
$table .= '<td>' . $direction . '</td>'; |
| 1126 |
if (in_array(strlen($data->caller_number), [10, 11])) { |
| 1127 |
if ($c_id != '') { |
| 1128 |
$table .= '<td><a href="javascript:void(0);" class="btn btn-info btn-sm" onclick="netgsm_sendSMS_bulkTab(\'' . $c_id . '\',\'' . $data->caller_number . '\'); ">Arayana SMS Gönder</a></td>'; |
| 1129 |
} else { |
| 1130 |
$table .= '<td><a href="javascript:void(0);" class="btn btn-info btn-sm" onclick="sendSMSglobal(\'' . $data->caller_number . '\'); ">Arayana SMS Gönder</a></td>'; |
| 1131 |
} |
| 1132 |
} else { |
| 1133 |
$table .= '<td></td>'; |
| 1134 |
} |
| 1135 |
$table .= '</tr>'; |
| 1136 |
} |
| 1137 |
$table .= '</tbody></table>'; |
| 1138 |
$message = $table; |
| 1139 |
$status = 'success'; |
| 1140 |
$type = 'SES'; |
| 1141 |
$info = $object->success->message; |
| 1142 |
} else { |
| 1143 |
if (is_object($object) && isset($object->error)) { |
| 1144 |
$status = 'error'; |
| 1145 |
$message = $object->error->message; |
| 1146 |
$info = $object->error->message; |
| 1147 |
} else { |
| 1148 |
$message = 'Bilinmeyen Hata oluştu.'; |
| 1149 |
$info = 'Bilinmeyen Hata oluştu.'; |
| 1150 |
$status = 'error'; |
| 1151 |
} |
| 1152 |
} |
| 1153 |
} else { |
| 1154 |
$status = 'error'; |
| 1155 |
$message = $object->error->message; |
| 1156 |
$info = $object->error->message; |
| 1157 |
} |
| 1158 |
} else { |
| 1159 |
$message = 'Bilinmeyen Hata oluştu.'; |
| 1160 |
$info = 'Bilinmeyen Hata oluştu.'; |
| 1161 |
$status = 'error'; |
| 1162 |
} |
| 1163 |
} |
| 1164 |
echo json_encode(['status' => $status, 'message' => $message, 'type' => $type, 'info' => $info]); |
| 1165 |
wp_die(); |
| 1166 |
} |
| 1167 |
|
| 1168 |
// Interval ekle |
| 1169 |
add_filter('cron_schedules', function($schedules) { |
| 1170 |
if (!isset($schedules['every_hour'])) { |
| 1171 |
$schedules['every_hour'] = [ |
| 1172 |
'interval' => 3600, // saniye cinsinden 1 saat |
| 1173 |
'display' => __('Every Hour') |
| 1174 |
]; |
| 1175 |
} |
| 1176 |
return $schedules; |
| 1177 |
}); |
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
// 1 saat ebir cron casısacak sekiide yapılandırdık |
| 1182 |
// Aktifleşince cron kur |
| 1183 |
register_activation_hook(__FILE__, function() { |
| 1184 |
if (!wp_next_scheduled('send_abandoned_cart_sms')) { |
| 1185 |
wp_schedule_event(time(), 'every_hour', 'send_abandoned_cart_sms'); |
| 1186 |
} |
| 1187 |
}); |
| 1188 |
|
| 1189 |
// Pasifleştirilince cron kaldır |
| 1190 |
register_deactivation_hook(__FILE__, function() { |
| 1191 |
$timestamp = wp_next_scheduled('send_abandoned_cart_sms'); |
| 1192 |
if ($timestamp) { |
| 1193 |
wp_unschedule_event($timestamp, 'send_abandoned_cart_sms'); |
| 1194 |
} |
| 1195 |
}); |
| 1196 |
|
| 1197 |
// Cron event fonksiyonu |
| 1198 |
add_action('send_abandoned_cart_sms', 'send_sms_for_abandoned_carts'); |
| 1199 |
function send_sms_for_abandoned_carts() { |
| 1200 |
$logger = wc_get_logger(); |
| 1201 |
|
| 1202 |
$bulkBody =""; |
| 1203 |
$control = get_option("netgsm_abandoned_card_sms_admin_control"); |
| 1204 |
$netgsm_status = get_option("netgsm_status"); |
| 1205 |
if(!$netgsm_status || !$control){ |
| 1206 |
return; |
| 1207 |
} |
| 1208 |
$message = trim((get_option("netgsm_abandoned_cart_to_admin_text"))); |
| 1209 |
$durationHours = (int) (get_option("netgsm_abandoned_cart_periyod") ?? 24); |
| 1210 |
$durationSecond = ($durationHours) * 60 * 60; |
| 1211 |
|
| 1212 |
|
| 1213 |
// Tüm kullanıcıları taramak yerine yalnızca sepet meta'sına sahip |
| 1214 |
// kullanıcıları getir (meta anahtarı: "{user_id}_last_cart_update"). |
| 1215 |
global $wpdb; |
| 1216 |
$cart_user_ids = $wpdb->get_col( |
| 1217 |
"SELECT DISTINCT user_id FROM {$wpdb->usermeta} WHERE meta_key LIKE '%\\_last\\_cart\\_update'" |
| 1218 |
); |
| 1219 |
foreach ($cart_user_ids as $user_id) { |
| 1220 |
$user = get_userdata($user_id); |
| 1221 |
if (!$user) continue; |
| 1222 |
$last_update_key = $user_id . '_last_cart_update'; |
| 1223 |
$last_cart_update = get_user_meta($user_id, $last_update_key, true); |
| 1224 |
if (!$last_cart_update) continue; |
| 1225 |
|
| 1226 |
$now = time(); |
| 1227 |
$last_cart_update_arr = json_decode($last_cart_update,true); |
| 1228 |
// Suan ile sepete son işlem yapılan sure farkı alındı timestamp olarak |
| 1229 |
$cart_duration = $now - intval($last_cart_update_arr['last_updated']); |
| 1230 |
$remaining_sms = intval($last_cart_update_arr['remaining_sms']); |
| 1231 |
if ($remaining_sms == 0) continue; |
| 1232 |
|
| 1233 |
if ($cart_duration >= $durationSecond ) { |
| 1234 |
|
| 1235 |
if( $netgsm_status ){ |
| 1236 |
$phone = get_user_meta($user_id, 'billing_phone', true); |
| 1237 |
if( $phone && $message !=""){ |
| 1238 |
$data['first_name']= get_user_meta($user->ID, 'first_name', true); |
| 1239 |
$data['last_name']= get_user_meta($user->ID, 'last_name', true); |
| 1240 |
$data['phone']= $phone; |
| 1241 |
$data['user_email']= $user->user_email; |
| 1242 |
$data['user_login']= $user->user_login; |
| 1243 |
$message = sanitize_textarea_field(wp_unslash($message)); |
| 1244 |
$message = strip_tags($message); |
| 1245 |
$data['message']= $message; |
| 1246 |
|
| 1247 |
$replace = new ReplaceFunction(); |
| 1248 |
$message = $replace->netgsm_replace_bulksms($data); |
| 1249 |
$bulkBody .= '<mp><msg><![CDATA[' . $message . ']]></msg><no>' . $phone . '</no></mp>'; |
| 1250 |
$last_update_key = $user_id . '_last_cart_update'; |
| 1251 |
$last_cart_update_arr['remaining_sms'] = $last_cart_update_arr['remaining_sms']-1; |
| 1252 |
$last_cart_update_arr['last_updated'] = time(); |
| 1253 |
update_user_meta($user_id, $last_update_key, json_encode($last_cart_update_arr)); |
| 1254 |
} |
| 1255 |
|
| 1256 |
} |
| 1257 |
} |
| 1258 |
} |
| 1259 |
// sms gonder |
| 1260 |
if($bulkBody != ""){ |
| 1261 |
$netgsm = new Netgsmsms(sanitize_text_field(get_option("netgsm_user")), sanitize_text_field(get_option("netgsm_pass")), sanitize_text_field(get_option('netgsm_input_smstitle')), sanitize_text_field(get_option("netgsm_trChar"))); |
| 1262 |
$json = $netgsm->sendBulkSMS($bulkBody); |
| 1263 |
} |
| 1264 |
} |
| 1265 |
|
| 1266 |
|
| 1267 |
add_action('woocommerce_cart_item_removed', 'update_last_cart_timestamp'); |
| 1268 |
add_action('woocommerce_after_cart_item_quantity_update', 'update_last_cart_timestamp'); |
| 1269 |
add_action('woocommerce_add_to_cart', 'update_last_cart_timestamp'); |
| 1270 |
function update_last_cart_timestamp() { |
| 1271 |
// urun eklendiginde veya last_updated ve remaining_sms guncelliyoruz. Musteri sepette urun unutur ise belirtilen aralıklar ile musteriye sms gonderiyoruz |
| 1272 |
if (is_user_logged_in()) { |
| 1273 |
$user_id = get_current_user_id(); |
| 1274 |
$meta_key = $user_id.'_last_cart_update'; |
| 1275 |
// Sepet boş mu kontrol et |
| 1276 |
$cart_contents = WC()->cart->get_cart_contents_count(); |
| 1277 |
$existing = get_user_meta($user_id, $meta_key, true); |
| 1278 |
$smslimit = (int) (get_option("netgsm_abandoned_cart_smslimit") ?? 1); |
| 1279 |
if ($cart_contents === 0) { |
| 1280 |
delete_user_meta($user_id, $meta_key); |
| 1281 |
}else{ |
| 1282 |
if (empty($existing)) { |
| 1283 |
// Meta verisi yoksa: yeni JSON verisi oluştur |
| 1284 |
$abandonedSetting = [ |
| 1285 |
'last_updated' => time(), |
| 1286 |
'remaining_sms' => $smslimit, |
| 1287 |
]; |
| 1288 |
add_user_meta($user_id, $meta_key, json_encode($abandonedSetting)); |
| 1289 |
} else { |
| 1290 |
// Meta verisi varsa: güncelle |
| 1291 |
$abandonedSetting = json_decode($existing, true); |
| 1292 |
if (!is_array($abandonedSetting)) { |
| 1293 |
$abandonedSetting = [ |
| 1294 |
'last_updated' => time(), |
| 1295 |
'remaining_sms' => $smslimit, |
| 1296 |
]; |
| 1297 |
} |
| 1298 |
|
| 1299 |
// JSON içeriğini güncelle |
| 1300 |
$abandonedSetting['last_updated'] = time(); |
| 1301 |
|
| 1302 |
update_user_meta($user_id, $meta_key, json_encode($abandonedSetting)); |
| 1303 |
} |
| 1304 |
} |
| 1305 |
} |
| 1306 |
} |
| 1307 |
|
| 1308 |
|
| 1309 |
add_filter('netgsm_contact_form_7_list', 'netgsm_wpcf7_form_list'); |
| 1310 |
function netgsm_wpcf7_form_list($arg = '') |
| 1311 |
{ |
| 1312 |
$list = get_posts(array( |
| 1313 |
'post_type' => 'wpcf7_contact_form', |
| 1314 |
'numberposts' => -1 |
| 1315 |
)); |
| 1316 |
|
| 1317 |
return $list; |
| 1318 |
} |
| 1319 |
|
| 1320 |
// Toplu SMS sekmesindeki kullanıcı tablosu için sunucu taraflı sayfalama. |
| 1321 |
// bootstrap-table (data-side-pagination="server") limit/offset/search gönderir; |
| 1322 |
// tüm kullanıcıları belleğe almadan sayfa sayfa döner. |
| 1323 |
add_action('wp_ajax_netgsm_users_datatable', 'netgsm_users_datatable'); |
| 1324 |
function netgsm_users_datatable() |
| 1325 |
{ |
| 1326 |
if ( ! isset($_POST['_wpnonce']) || ! wp_verify_nonce( $_POST['_wpnonce'], 'netgsm_users_datatable' ) ) { |
| 1327 |
wp_die(); |
| 1328 |
} |
| 1329 |
if ( ! current_user_can('edit_pages') ) { |
| 1330 |
wp_die(); |
| 1331 |
} |
| 1332 |
|
| 1333 |
$phone_meta = sanitize_text_field(get_option("netgsm_contact_meta_key")); |
| 1334 |
if (empty($phone_meta)) { |
| 1335 |
$phone_meta = 'billing_phone'; |
| 1336 |
} |
| 1337 |
|
| 1338 |
$limit = isset($_POST['limit']) ? (int) $_POST['limit'] : 25; |
| 1339 |
$offset = isset($_POST['offset']) ? (int) $_POST['offset'] : 0; |
| 1340 |
$search = isset($_POST['search']) ? sanitize_text_field(wp_unslash($_POST['search'])) : ''; |
| 1341 |
if ($limit <= 0) { $limit = 25; } |
| 1342 |
if ($offset < 0) { $offset = 0; } |
| 1343 |
|
| 1344 |
// Yalnızca telefonu (contact meta) dolu kullanıcılar listelenir. |
| 1345 |
$args = array( |
| 1346 |
'number' => $limit, |
| 1347 |
'offset' => $offset, |
| 1348 |
'orderby' => 'ID', |
| 1349 |
'order' => 'ASC', |
| 1350 |
'count_total' => true, |
| 1351 |
'fields' => 'all', |
| 1352 |
'meta_query' => array( |
| 1353 |
array('key' => $phone_meta, 'value' => '', 'compare' => '!='), |
| 1354 |
), |
| 1355 |
); |
| 1356 |
|
| 1357 |
if ($search !== '') { |
| 1358 |
if (preg_match('/^\+?[0-9\s]+$/', $search)) { |
| 1359 |
// Numara araması: telefon meta'sında ara |
| 1360 |
$args['meta_query'] = array( |
| 1361 |
'relation' => 'AND', |
| 1362 |
array('key' => $phone_meta, 'value' => '', 'compare' => '!='), |
| 1363 |
array('key' => $phone_meta, 'value' => preg_replace('/\s+/', '', $search), 'compare' => 'LIKE'), |
| 1364 |
); |
| 1365 |
} else { |
| 1366 |
// Metin araması: kullanıcı adı / e-posta / görünen ad |
| 1367 |
$args['search'] = '*' . $search . '*'; |
| 1368 |
$args['search_columns'] = array('user_login', 'user_email', 'display_name', 'user_nicename'); |
| 1369 |
} |
| 1370 |
} |
| 1371 |
|
| 1372 |
$query = new WP_User_Query($args); |
| 1373 |
$rows = array(); |
| 1374 |
foreach ($query->get_results() as $user) { |
| 1375 |
$first = get_user_meta($user->ID, 'first_name', true); |
| 1376 |
$last = get_user_meta($user->ID, 'last_name', true); |
| 1377 |
$name = trim($first . ' ' . $last); |
| 1378 |
$rows[] = array( |
| 1379 |
'userid' => (int) $user->ID, |
| 1380 |
'username' => $user->display_name, |
| 1381 |
'name' => $name !== '' ? $name : '—', |
| 1382 |
'email' => $user->user_email, |
| 1383 |
'phone' => get_user_meta($user->ID, $phone_meta, true), |
| 1384 |
); |
| 1385 |
} |
| 1386 |
|
| 1387 |
wp_send_json(array( |
| 1388 |
'total' => (int) $query->get_total(), |
| 1389 |
'totalNotFiltered' => (int) $query->get_total(), |
| 1390 |
'rows' => $rows, |
| 1391 |
)); |
| 1392 |
} |
| 1393 |
|
| 1394 |
add_action('wp_ajax_netgsm_sendSMS_bulkTab', 'netgsm_sendSMS_bulkTab'); |
| 1395 |
function netgsm_sendSMS_bulkTab() |
| 1396 |
{ |
| 1397 |
|
| 1398 |
if ( ! wp_verify_nonce( $_POST['_wpnonce'], 'netgsm_sendSMS_bulkTab' ) ) { |
| 1399 |
wp_die(); |
| 1400 |
} |
| 1401 |
|
| 1402 |
$phones = ""; |
| 1403 |
$json = array(); |
| 1404 |
$phone_meta = 'billing_phone'; // Varsayılan değer |
| 1405 |
|
| 1406 |
$contact_meta_key = sanitize_text_field(get_option("netgsm_contact_meta_key")); |
| 1407 |
|
| 1408 |
// Check if the option is not empty |
| 1409 |
if (!empty($contact_meta_key)) { |
| 1410 |
$phone_meta = $contact_meta_key; |
| 1411 |
} |
| 1412 |
if (isset($_POST['users']) && isset($_POST['message'])) { |
| 1413 |
// Users input'unu temizle |
| 1414 |
$users_raw = sanitize_text_field($_POST['users']); |
| 1415 |
$users = array_map('sanitize_text_field', explode(',', rtrim($users_raw, ','))); |
| 1416 |
|
| 1417 |
$bulkBody = ""; |
| 1418 |
$messageContent = sanitize_textarea_field(wp_unslash($_POST['message'])); |
| 1419 |
$messageContent = strip_tags($messageContent); |
| 1420 |
$filter = sanitize_text_field(wp_unslash($_POST['filter'])); |
| 1421 |
$replace = new ReplaceFunction(); |
| 1422 |
foreach ($users as $userID) { |
| 1423 |
$phones .= $replace->netgsm_spaceTrim(get_user_meta($userID, $phone_meta, true)) . ","; |
| 1424 |
$sendedPhone = get_user_meta($userID, $phone_meta, true); |
| 1425 |
$sendPhone = isset($_POST['sendPhone']) ? $_POST['sendPhone'] : 0; |
| 1426 |
if($userID==0 && $sendPhone !=0){ |
| 1427 |
$sendedPhone = sanitize_text_field($sendPhone); |
| 1428 |
} |
| 1429 |
$userinfo = get_userdata($userID); |
| 1430 |
$data = array( |
| 1431 |
'first_name' => $userinfo->first_name ??"", |
| 1432 |
'last_name' => $userinfo->last_name??"", |
| 1433 |
'user_login' => $userinfo->user_login??"", |
| 1434 |
'phone' => $sendedPhone, |
| 1435 |
'user_email' => $userinfo->user_email??"", |
| 1436 |
'message' => $messageContent, |
| 1437 |
'filter' => $filter |
| 1438 |
); |
| 1439 |
$message = $replace->netgsm_replace_bulksms($data); |
| 1440 |
$message = $replace->netgsm_replace_date($message); |
| 1441 |
|
| 1442 |
$bulkBody .= '<mp><msg><![CDATA[' . $message . ']]></msg><no>' . $data['phone'] . '</no></mp>'; |
| 1443 |
} |
| 1444 |
$phones = rtrim($phones, ','); |
| 1445 |
$netgsm = new Netgsmsms(sanitize_text_field(get_option("netgsm_user")), sanitize_text_field(get_option("netgsm_pass")), sanitize_text_field(get_option('netgsm_input_smstitle')), sanitize_text_field(get_option("netgsm_trChar"))); |
| 1446 |
$json = $netgsm->sendBulkSMS($bulkBody, $_POST['filter']); |
| 1447 |
$json['phones'] = $sendedPhone; |
| 1448 |
} else { |
| 1449 |
$json['durum'] = '0'; |
| 1450 |
$json['mesaj'] = 'Sms gönderimi başarısız.'; |
| 1451 |
} |
| 1452 |
echo json_encode($json); |
| 1453 |
wp_die(); |
| 1454 |
} |
| 1455 |
|
| 1456 |
add_action('wp_ajax_netgsm_sendsms', 'netgsm_sendsms'); |
| 1457 |
function netgsm_sendsms() |
| 1458 |
{ |
| 1459 |
|
| 1460 |
if ( ! wp_verify_nonce( $_POST['_wpnonce'], 'netgsm_sendsms' ) ) { |
| 1461 |
wp_die(); |
| 1462 |
} |
| 1463 |
|
| 1464 |
$json = array(); |
| 1465 |
$replace = new ReplaceFunction(); |
| 1466 |
if (isset($_POST['phone']) && isset($_POST['message'])) { |
| 1467 |
$message = sanitize_textarea_field(wp_unslash($_POST['message'])); |
| 1468 |
$message = strip_tags($message); |
| 1469 |
$netgsm = new Netgsmsms(sanitize_text_field(get_option("netgsm_user")), sanitize_text_field(get_option("netgsm_pass")), sanitize_text_field(get_option('netgsm_input_smstitle')), sanitize_text_field(get_option("netgsm_trChar"))); |
| 1470 |
$json = $netgsm->sendSMS(sanitize_text_field($replace->netgsm_spaceTrim($_POST['phone'])), $message, sanitize_text_field($_POST['filter'])); |
| 1471 |
//netgsm_setData($_POST['phone'], get_option('netgsm_input_smstitle'), get_option("netgsm_trChar"), $_POST['message'], 'ÖzelSMS', date('Y-m-d H:i:s'), $json['gorevid'], 0 ); |
| 1472 |
} else { |
| 1473 |
$json['durum'] = '0'; |
| 1474 |
$json['mesaj'] = 'Sms gönderimi başarısız.'; |
| 1475 |
} |
| 1476 |
echo json_encode($json); |
| 1477 |
wp_die(); |
| 1478 |
} |
| 1479 |
add_action('wp_ajax_nopriv_netgsm_netasistanticket', 'netgsm_netasistanticket'); |
| 1480 |
add_action('wp_ajax_netgsm_netasistanticket', 'netgsm_netasistanticket'); |
| 1481 |
function netgsm_netasistanticket() |
| 1482 |
{ |
| 1483 |
$json = array(); |
| 1484 |
$replace = new ReplaceFunction(); |
| 1485 |
date_default_timezone_set('Europe/Istanbul'); |
| 1486 |
if (isset($_POST['netasistan_name']) && isset($_POST['netasistan_lastname']) && isset($_POST['netasistan_number']) && isset($_POST['netasistan_header']) && isset($_POST['netasistan_content']) && isset($_POST['netasistan_email'])) { |
| 1487 |
if (sanitize_text_field(get_option('netgsm_netasistan_appkey')) != "" && sanitize_text_field(get_option('netgsm_netasistan_etiket')) != "" && sanitize_text_field(get_option('netgsm_netasistan_userkey')) != "") { |
| 1488 |
$netgsm = new Netgsmsms(sanitize_text_field(get_option("netgsm_user")), sanitize_text_field(get_option("netgsm_pass")), sanitize_text_field(get_option('netgsm_input_smstitle')), sanitize_text_field(get_option("netgsm_trChar"))); |
| 1489 |
if (sanitize_text_field(get_option('netgsm_netasistan_token')) != "" && sanitize_text_field(get_option('netgsm_netasistan_tokendate')) != "") { |
| 1490 |
if (strtotime(get_option('netgsm_netasistan_tokendate')) > strtotime(date('d-m-Y H:i:s'))) { |
| 1491 |
$tokenvalue = sanitize_text_field(get_option('netgsm_netasistan_token')); |
| 1492 |
} else { |
| 1493 |
$netasistan_token = $netgsm->netasistan_yenitoken(sanitize_text_field(get_option('netgsm_netasistan_appkey')), sanitize_text_field(get_option('netgsm_netasistan_userkey'))); |
| 1494 |
$token = json_decode($netasistan_token['body'], true); |
| 1495 |
update_option('netgsm_netasistan_token', $token['data']['access_token'], false); |
| 1496 |
update_option('netgsm_netasistan_tokendate', $token['data']['expired_at'], false); |
| 1497 |
$tokenvalue = $token['data']['access_token']; |
| 1498 |
} |
| 1499 |
} else { |
| 1500 |
$netasistan_token = $netgsm->netasistan_yenitoken(sanitize_text_field(get_option('netgsm_netasistan_appkey')), sanitize_text_field(get_option('netgsm_netasistan_userkey'))); |
| 1501 |
$token = json_decode($netasistan_token['body'], true); |
| 1502 |
update_option('netgsm_netasistan_token', $token['data']['access_token']); |
| 1503 |
update_option('netgsm_netasistan_tokendate', $token['data']['expired_at']); |
| 1504 |
$tokenvalue = $token['data']['access_token']; |
| 1505 |
} |
| 1506 |
if (isset($tokenvalue)) { |
| 1507 |
$netasistan_etiketler = sanitize_text_field(get_option('netgsm_netasistan_etiket')); |
| 1508 |
$netasistan_etiketler = explode(",", $netasistan_etiketler); |
| 1509 |
$netgsm = new Netgsmsms(sanitize_text_field(get_option("netgsm_user")), sanitize_text_field(get_option("netgsm_pass")), sanitize_text_field(get_option('netgsm_input_smstitle')), sanitize_text_field(get_option("netgsm_trChar"))); |
| 1510 |
$json = $netgsm->netasistan_ticket(sanitize_text_field($_POST['netasistan_name']), sanitize_text_field($_POST['netasistan_lastname']), sanitize_text_field($replace->netgsm_spaceTrim(netasistan_phonecontrol($_POST['netasistan_number']))), sanitize_text_field($_POST['netasistan_email']), wp_unslash($_POST['netasistan_header']), wp_unslash(sanitize_text_field($_POST['netasistan_content'])), $netasistan_etiketler, $tokenvalue); |
| 1511 |
echo esc_html($json['body']); |
| 1512 |
} else { |
| 1513 |
$json = array( |
| 1514 |
'code' => '0', |
| 1515 |
'mesaj' => 'Kayıt oluşturulamadı.' |
| 1516 |
); |
| 1517 |
echo json_encode($json); |
| 1518 |
} |
| 1519 |
} else { |
| 1520 |
$json = array( |
| 1521 |
'code' => '0', |
| 1522 |
'mesaj' => 'Kayıt oluşturulamadı.' |
| 1523 |
); |
| 1524 |
echo json_encode($json); |
| 1525 |
} |
| 1526 |
} else { |
| 1527 |
$json = array( |
| 1528 |
'code' => '0', |
| 1529 |
'mesaj' => 'Kayıt oluşturulamadı.' |
| 1530 |
); |
| 1531 |
echo json_encode($json); |
| 1532 |
} |
| 1533 |
wp_die(); |
| 1534 |
} |
| 1535 |
|
| 1536 |
function netgsm_newcustomer_control() |
| 1537 |
{ |
| 1538 |
$newuser1 = esc_html(get_option("netgsm_newuser_to_admin_control")); |
| 1539 |
$newuser2 = esc_html(get_option("netgsm_newuser_to_customer_control")); |
| 1540 |
$newuser3 = esc_html(get_option("netgsm_rehber_control")); |
| 1541 |
$newuser4 = esc_html(get_option("netgsm_tf2_auth_register_control")); |
| 1542 |
$newuser5 = esc_html(get_option("netgsm_iys_check_control")); |
| 1543 |
$control = 0; |
| 1544 |
if (isset($newuser1) && !empty($newuser1) && $newuser1 == 1) { |
| 1545 |
$control = 1; |
| 1546 |
} elseif (isset($newuser2) && !empty($newuser2) && $newuser2 == 1) { |
| 1547 |
$control = 2; |
| 1548 |
} elseif (isset($newuser3) && !empty($newuser3) && $newuser3 == 1) { |
| 1549 |
$control = 3; |
| 1550 |
} elseif (isset($newuser4) && !empty($newuser4) && $newuser4 == 1) { |
| 1551 |
$control = 4; |
| 1552 |
} elseif (isset($newuser5) && !empty($newuser5) && $newuser5 == 1) { |
| 1553 |
$control = 5; |
| 1554 |
} |
| 1555 |
return $control; |
| 1556 |
} |
| 1557 |
|
| 1558 |
add_action('woocommerce_register_form', 'netgsm_custom_register_form'); |
| 1559 |
function netgsm_custom_register_form() |
| 1560 |
{ |
| 1561 |
$netgsm_status = esc_html(get_option("netgsm_status")); |
| 1562 |
$netgsm_phonenumber_zero = esc_html(get_option("netgsm_phonenumber_zero1")); |
| 1563 |
$control = netgsm_newcustomer_control(); |
| 1564 |
$otpregister_control = esc_html(get_option("netgsm_tf2_auth_register_control")); |
| 1565 |
if (isset($netgsm_status) && !empty($netgsm_status) && $netgsm_status == 1 && ($control != 0 || $otpregister_control == 1)) { |
| 1566 |
?> |
| 1567 |
<?php |
| 1568 |
// Ayar acikken (sadece telefon iste) ad/soyad alanlari hic gosterilmez |
| 1569 |
$name_optional = esc_html(get_option('netgsm_tf2_name_optional')); |
| 1570 |
if ($name_optional != 1) { |
| 1571 |
?> |
| 1572 |
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide"> |
| 1573 |
<label for="first_name"><?php esc_html_e('Adınız', 'mydomain') ?><span |
| 1574 |
class="required">*</span><br /> |
| 1575 |
<input type="text" name="first_name" id="first_name" class="input-text form-control" |
| 1576 |
value="<?php echo esc_html_e(@$_POST['first_name']) ?>" required /></label> |
| 1577 |
</p> |
| 1578 |
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide"> |
| 1579 |
<label for="last_name"><?php esc_html_e('Soyadınız', 'mydomain') ?><span |
| 1580 |
class="required">*</span><br /> |
| 1581 |
<input type="text" name="last_name" id="last_name" class="input-text form-control" |
| 1582 |
value="<?php echo esc_html_e(@$_POST['last_name']) ?>" required /></label> |
| 1583 |
</p> |
| 1584 |
<?php } ?> |
| 1585 |
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide"> |
| 1586 |
<label for="billing_phone"><?php esc_html_e('Cep Telefonu', 'mydomain') ?><span |
| 1587 |
class="required">*</span><br /> |
| 1588 |
<input type="tel" name="billing_phone" id="billing_phone" class="input-text form-control" |
| 1589 |
value="<?php if ($netgsm_phonenumber_zero == 1) { |
| 1590 |
echo '0'; |
| 1591 |
} ?><?php echo esc_html_e(@$_POST['billing_phone']) ?>" required /> |
| 1592 |
<?php |
| 1593 |
$netgsm_status = esc_html(get_option("netgsm_status")); |
| 1594 |
if (isset($netgsm_status) && !empty($netgsm_status) && $netgsm_status == 1) { |
| 1595 |
|
| 1596 |
if ($otpregister_control == 1) { |
| 1597 |
?> |
| 1598 |
<input type="button" name="sendCode" id="sendCode" class="input-text" onclick="sendtf2Code(jQuery('#billing_phone').val());" |
| 1599 |
value="Doğrulama kodu gönder" /> |
| 1600 |
<?php |
| 1601 |
} |
| 1602 |
} |
| 1603 |
?> |
| 1604 |
|
| 1605 |
</label> |
| 1606 |
</p> |
| 1607 |
<?php |
| 1608 |
$netgsm_status = esc_html(get_option("netgsm_status")); |
| 1609 |
if (isset($netgsm_status) && !empty($netgsm_status) && $netgsm_status == 1) { |
| 1610 |
$otpregister_control = esc_html(get_option("netgsm_tf2_auth_register_control")); |
| 1611 |
if ($otpregister_control == 1) { |
| 1612 |
?> |
| 1613 |
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide"> |
| 1614 |
<label for="tf2Code"><?php esc_html_e('Doğrulama Kodu:', 'mydomain') ?><span |
| 1615 |
class="required">*</span><br /> |
| 1616 |
<input type="text" name="tf2Code" id="tf2Code" class="input-text form-control" |
| 1617 |
value="" required /> |
| 1618 |
<label for=""><i><small id="tf2Codealert"></small></i></label> |
| 1619 |
</label> |
| 1620 |
|
| 1621 |
</p> |
| 1622 |
<?php |
| 1623 |
} |
| 1624 |
|
| 1625 |
$iys_status = esc_html(get_option("netgsm_iys_check_control")); |
| 1626 |
if ($iys_status == 1) { |
| 1627 |
?> |
| 1628 |
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide"> |
| 1629 |
<input type="checkbox" name="netgsm_iys" id="netgsm_iys" value="1" /> <?php echo esc_html(get_option("netgsm_iys_check_text")); ?> |
| 1630 |
|
| 1631 |
</p> |
| 1632 |
<?php |
| 1633 |
} |
| 1634 |
} |
| 1635 |
} |
| 1636 |
} |
| 1637 |
|
| 1638 |
add_action('woocommerce_register_form', 'netgsm_ajaxRegister'); |
| 1639 |
function netgsm_ajaxRegister() |
| 1640 |
{ |
| 1641 |
$netgsm_phonenumber_zero = esc_html(get_option("netgsm_phonenumber_zero1")); |
| 1642 |
?> |
| 1643 |
<script type="text/javascript"> |
| 1644 |
function sendtf2Code(phone) { |
| 1645 |
var firstname = jQuery('#first_name').val(); |
| 1646 |
var lastname = jQuery('#last_name').val(); |
| 1647 |
var email = jQuery("input[name*='email']").val(); |
| 1648 |
|
| 1649 |
var error = ''; |
| 1650 |
<?php if (esc_html(get_option('netgsm_tf2_name_optional')) != 1) { ?> |
| 1651 |
if (firstname == '') { |
| 1652 |
error += '> İsim girilmedi.\n'; |
| 1653 |
} |
| 1654 |
if (lastname == '') { |
| 1655 |
error += '> Soyisim girilmedi.\n'; |
| 1656 |
} |
| 1657 |
if (email == '') { |
| 1658 |
error += '> E-mail adresi girilmedi.\n'; |
| 1659 |
} |
| 1660 |
<?php } ?> |
| 1661 |
if (phone == '') { |
| 1662 |
error += '> Telefon numarası girilmedi.\n'; |
| 1663 |
} |
| 1664 |
|
| 1665 |
<?php |
| 1666 |
if ($netgsm_phonenumber_zero == 1) { |
| 1667 |
?> |
| 1668 |
if (phone.slice(0, 1) != '0') { |
| 1669 |
error += '> Telefon numarası 0 ile başlamalıdır.\n'; |
| 1670 |
} |
| 1671 |
<?php |
| 1672 |
} |
| 1673 |
?> |
| 1674 |
|
| 1675 |
if (error != '') { |
| 1676 |
alert('Aşağıdaki hatalar alındı : \n\n' + error); |
| 1677 |
return false; |
| 1678 |
} |
| 1679 |
|
| 1680 |
var data = { |
| 1681 |
'action': 'netgsm_sendtf2SMS', |
| 1682 |
'phone': phone, |
| 1683 |
'first_name': firstname, |
| 1684 |
'last_name': lastname, |
| 1685 |
'email': email |
| 1686 |
}; |
| 1687 |
|
| 1688 |
jQuery.post(ajaxurl, data, function(response) { |
| 1689 |
var endChar = response.substring(response.length - 1); |
| 1690 |
if (endChar == '0') { |
| 1691 |
response = response.substring(0, (response.length - 1)); |
| 1692 |
} |
| 1693 |
var obje = JSON.parse(response); |
| 1694 |
if (obje.status == 'success') { |
| 1695 |
alert('Lütfen ' + obje.phone + ' numaralı telefonunuza gelen güvenlik kodunu giriniz.'); |
| 1696 |
jQuery('#tf2Codealert').html('*Lütfen ' + obje.phone + ' numaralı telefonunuza gelen ' + obje.refno + ' referans numaralı güvenlik kodunu giriniz.'); |
| 1697 |
document.getElementById("tf2Code").focus(); |
| 1698 |
jQuery('#sendCode').prop('disabled', true); |
| 1699 |
} else { |
| 1700 |
if (obje.status == 'error' && obje.state == 1) { |
| 1701 |
alert(obje.data + ' Lütfen site yöneticisi ile iletişime geçin.'); |
| 1702 |
} else if (obje.status == 'error' && obje.state == 2) { |
| 1703 |
alert(obje.data); |
| 1704 |
} else if (obje.status == 'error' && obje.state == 4) { |
| 1705 |
alert(obje.data); |
| 1706 |
} else if (obje.status == 'error' && obje.state == 5) { |
| 1707 |
alert(obje.data); |
| 1708 |
} else { |
| 1709 |
alert('Bilinmeyen bir hata oluştu. GSM numarası girdiğinize emin olun. Sorunun devam etmesi halinde lütfen site yöneticisi ile iletişime geçin.'); |
| 1710 |
} |
| 1711 |
} |
| 1712 |
}); |
| 1713 |
} |
| 1714 |
</script> |
| 1715 |
<?php |
| 1716 |
} |
| 1717 |
|
| 1718 |
add_action('wp_ajax_netgsm_sendtf2SMS', 'netgsm_sendtf2SMS'); |
| 1719 |
function netgsm_sendtf2SMS() |
| 1720 |
{ |
| 1721 |
$authKey = rand(10000, 99999); |
| 1722 |
$refno = substr(md5(uniqid()), 0, 5); |
| 1723 |
$phone = sanitize_text_field($_POST['phone']); |
| 1724 |
ltrim($phone, '0'); |
| 1725 |
$replace = new ReplaceFunction(); |
| 1726 |
// Kapıda ödeme ise is_cod true yap. Register işleminde false olacak |
| 1727 |
$is_cod = isset($_POST['type']) && sanitize_text_field($_POST['type']) == 'cod' ? true : false; |
| 1728 |
|
| 1729 |
$phone_control = sanitize_text_field(get_option('netgsm_tf2_auth_register_phone_control')); |
| 1730 |
if ($phone_control == 1 && !$is_cod) { // kayıtlı numara kontrolü yapılacak |
| 1731 |
$args = array( |
| 1732 |
'order' => 'DESC', |
| 1733 |
'orderby' => 'ID', |
| 1734 |
'number' => 1, //limit |
| 1735 |
'meta_query' => array( |
| 1736 |
'relation' => 'OR', |
| 1737 |
array( |
| 1738 |
'key' => 'billing_phone', |
| 1739 |
'value' => trim($phone, '0'), |
| 1740 |
'compare' => 'LIKE' |
| 1741 |
) |
| 1742 |
) |
| 1743 |
); |
| 1744 |
$query = new WP_User_Query($args); |
| 1745 |
$results = $query->get_results(); |
| 1746 |
if (is_array($results) && $results != null && isset($results[0])) { // kayıtlı numara var |
| 1747 |
$phone_warning_text = sanitize_text_field(get_option('netgsm_tf2_auth_register_phone_warning_text')); |
| 1748 |
$newVar = []; |
| 1749 |
$oldVar = []; |
| 1750 |
array_push($oldVar, '[telefon_no]'); |
| 1751 |
array_push($oldVar, '[ad]'); |
| 1752 |
array_push($oldVar, '[soyad]'); |
| 1753 |
array_push($oldVar, '[mail]'); |
| 1754 |
|
| 1755 |
$newVar['telefon_no'] = isset($_POST['phone']) ? sanitize_text_field($_POST['phone']) : ''; |
| 1756 |
$newVar['ad'] = isset($_POST['first_name']) ? sanitize_text_field($_POST['first_name']) : ''; |
| 1757 |
$newVar['soyad'] = isset($_POST['last_name']) ? sanitize_text_field($_POST['last_name']) : ''; |
| 1758 |
$newVar['mail'] = isset($_POST['email']) ? sanitize_text_field($_POST['email']) : ''; |
| 1759 |
|
| 1760 |
$phone_warning_text = $replace->netgsm_replace_array($oldVar, $newVar, $phone_warning_text); |
| 1761 |
echo json_encode(['status' => 'error', 'state' => '5', 'data' => $phone_warning_text]); |
| 1762 |
die; |
| 1763 |
} else { |
| 1764 |
} |
| 1765 |
} |
| 1766 |
|
| 1767 |
$netgsm_status = esc_html(get_option("netgsm_status")); |
| 1768 |
if (isset($netgsm_status) && !empty($netgsm_status) && $netgsm_status == 1) { |
| 1769 |
if ($phone != '' && in_array(strlen($phone), [10, 11])) { |
| 1770 |
if ($is_cod) { |
| 1771 |
$otpregister_control = esc_html(get_option('netgsm_tf2_cash_on_delivery_control')); |
| 1772 |
} else { |
| 1773 |
$otpregister_control = esc_html(get_option("netgsm_tf2_auth_register_control")); |
| 1774 |
} |
| 1775 |
if ($otpregister_control == 1) { |
| 1776 |
$first_name = isset($_POST['first_name']) ? sanitize_text_field($_POST['first_name']) : ''; |
| 1777 |
$last_name = isset($_POST['last_name']) ? sanitize_text_field($_POST['last_name']) : ''; |
| 1778 |
$email = isset($_POST['email']) ? sanitize_text_field($_POST['email']) : ''; |
| 1779 |
|
| 1780 |
$code = get_post_meta(1, $phone . '_2fa', true); |
| 1781 |
|
| 1782 |
date_default_timezone_set('Europe/Istanbul'); |
| 1783 |
if ($code != '') { |
| 1784 |
$sendTime = get_post_meta(1, $phone . '_2fa_time', true); |
| 1785 |
$sendTime = strtotime($sendTime); |
| 1786 |
$now = time(); |
| 1787 |
$diff = $now - $sendTime; |
| 1788 |
|
| 1789 |
if ($is_cod) { |
| 1790 |
$savedDiff = esc_html(get_option("netgsm_tf2_cash_on_delivery_diff")); |
| 1791 |
} else { |
| 1792 |
$savedDiff = esc_html(get_option("netgsm_tf2_auth_register_diff"));; |
| 1793 |
} |
| 1794 |
if ($savedDiff == '' || !is_numeric($savedDiff)) { |
| 1795 |
$savedDiff = 180; |
| 1796 |
} |
| 1797 |
|
| 1798 |
if ($diff > $savedDiff) { |
| 1799 |
update_post_meta(1, $phone . '_2fa', $authKey); |
| 1800 |
update_post_meta(1, $phone . '_2fa_time', date('Y-m-d H:i:s', time())); |
| 1801 |
update_post_meta(1, $phone . '_2fa_ref', $refno); |
| 1802 |
} else { |
| 1803 |
$savedRefNo = get_post_meta(1, $phone . '_2fa_ref', true); |
| 1804 |
echo json_encode(['status' => 'error', 'state' => 4, 'data' => 'Daha önce ' . $phone . ' numarasına ' . $savedRefNo . ' referans numaralı doğrulama kodu gönderilmiş. Lütfen gönderilmiş güvenlik kodunu girininiz.Yeni dogrulama kodu icin Gönderme zamanından : ' . date('d.m.Y H:i', $sendTime) . " $savedDiff sn bekleyiniz ", 'phone' => $phone]); |
| 1805 |
die; |
| 1806 |
} |
| 1807 |
} else { |
| 1808 |
add_post_meta(1, $phone . '_2fa', $authKey, ''); |
| 1809 |
add_post_meta(1, $phone . '_2fa_time', date('Y-m-d H:i:s', time())); |
| 1810 |
add_post_meta(1, $phone . '_2fa_ref', $refno); |
| 1811 |
} |
| 1812 |
if ($is_cod) { |
| 1813 |
$messageContent = sanitize_textarea_field(wp_unslash(get_option("netgsm_tf2_cash_on_delivery_text"))); |
| 1814 |
} else { |
| 1815 |
$messageContent = sanitize_textarea_field(wp_unslash(get_option("netgsm_tf2_auth_register_text")));; |
| 1816 |
} |
| 1817 |
$messageContent = strip_tags($messageContent); |
| 1818 |
$data = array( |
| 1819 |
'first_name' => $first_name, |
| 1820 |
'last_name' => $last_name, |
| 1821 |
'phone' => $phone, |
| 1822 |
'user_email' => $email, |
| 1823 |
'otpcode' => $authKey, |
| 1824 |
'refno' => $refno, |
| 1825 |
'message' => $messageContent |
| 1826 |
); |
| 1827 |
$message = $replace->netgsm_replace_twofactorauth_text($data); |
| 1828 |
$message = $replace->netgsm_replace_date($message); |
| 1829 |
|
| 1830 |
$netgsm = $netgsm = new Netgsmsms(sanitize_text_field(get_option("netgsm_user")), sanitize_text_field(get_option("netgsm_pass")), sanitize_text_field(get_option('netgsm_input_smstitle')), sanitize_text_field(get_option("netgsm_trChar"))); |
| 1831 |
|
| 1832 |
$result = $netgsm->sendOTPSMS($phone, $message); |
| 1833 |
|
| 1834 |
if ($result['kod'] == '00') { |
| 1835 |
echo json_encode(['status' => 'success', 'data' => 'Doğrulama gönderildi.', 'phone' => $phone, 'refno' => $refno]); |
| 1836 |
} else { |
| 1837 |
update_post_meta(1, $phone . '_2fa_time', '1970-01-01 12:12:12'); |
| 1838 |
echo json_encode(['status' => 'error', 'state' => '1', 'data' => 'Doğrulama kodu gönderilemedi. ' . $result['mesaj'] ?? '']); |
| 1839 |
} |
| 1840 |
} else { |
| 1841 |
echo json_encode(['status' => 'error', 'state' => '3', 'data' => 'OTP kontrol açık değil.']); |
| 1842 |
} |
| 1843 |
} else { |
| 1844 |
echo json_encode(['status' => 'error', 'state' => '2', 'data' => 'Telefon numarası hatalı']); |
| 1845 |
} |
| 1846 |
} |
| 1847 |
} |
| 1848 |
|
| 1849 |
add_action('wp_enqueue_scripts', 'netgsm_admin_scripts'); |
| 1850 |
add_action('wp_ajax_nopriv_netgsm_sendtf2SMS', 'netgsm_sendtf2SMS'); |
| 1851 |
function netgsm_admin_scripts() |
| 1852 |
{ |
| 1853 |
$netgsm_status = esc_html(get_option("netgsm_status")); |
| 1854 |
if (isset($netgsm_status) && !empty($netgsm_status) && $netgsm_status == 1) { |
| 1855 |
$otpregister_control = esc_html(get_option("netgsm_tf2_auth_register_control")); |
| 1856 |
if ($otpregister_control == 1 || get_option('netgsm_asistan') == '1') { |
| 1857 |
// JavaScript dosyasını yükle |
| 1858 |
wp_enqueue_script('script', plugins_url('ajax.js', dirname(__FILE__) . '/lib/js/1/'), array('jquery'), '1.0', true); |
| 1859 |
|
| 1860 |
// `ajaxurl` değişkenini tanımla |
| 1861 |
$inline_script = 'const ajaxurl = ' . json_encode(admin_url('admin-ajax.php')) . ';'; |
| 1862 |
wp_add_inline_script('script', $inline_script, 'before'); |
| 1863 |
} |
| 1864 |
} |
| 1865 |
} |
| 1866 |
|
| 1867 |
add_filter('woocommerce_process_registration_errors', 'netgsm_custom_registration_errors', 10, 1); //telefon numarası girilmemişse |
| 1868 |
function netgsm_custom_registration_errors($validation_error) |
| 1869 |
{ |
| 1870 |
if (isset($_POST['fname']) && isset($_POST['lname'])) { |
| 1871 |
return $validation_error; |
| 1872 |
} |
| 1873 |
|
| 1874 |
$netgsm_status = esc_html(get_option("netgsm_status")); |
| 1875 |
$billing_phone = isset($_POST['billing_phone']) ? sanitize_text_field($_POST['billing_phone']) : '0'; |
| 1876 |
|
| 1877 |
|
| 1878 |
$first_name = !empty($_POST['first_name']) ? sanitize_text_field($_POST['first_name']) : '0'; |
| 1879 |
$last_name = !empty($_POST['last_name']) ? sanitize_text_field($_POST['last_name']) : '0'; |
| 1880 |
$control = netgsm_newcustomer_control(); |
| 1881 |
|
| 1882 |
$netgsm_status = esc_html(get_option("netgsm_status")); |
| 1883 |
$otpstatus = false; |
| 1884 |
if (isset($netgsm_status) && !empty($netgsm_status) && $netgsm_status == 1) { |
| 1885 |
$otpregister_control = esc_html(get_option("netgsm_tf2_auth_register_control")); |
| 1886 |
if ($otpregister_control == 1) { |
| 1887 |
$otpstatus = true; |
| 1888 |
} |
| 1889 |
} |
| 1890 |
|
| 1891 |
$code = ''; |
| 1892 |
$tf2Code = ''; |
| 1893 |
if ($otpstatus) { |
| 1894 |
$tf2Code = isset($_POST['tf2Code']) ? sanitize_text_field($_POST['tf2Code']) : ''; |
| 1895 |
$code = get_post_meta(1, $billing_phone . '_2fa', true) ?: ''; |
| 1896 |
} |
| 1897 |
$netgsm_phonenumber_zero = esc_html(get_option("netgsm_phonenumber_zero1")); |
| 1898 |
$delete = true; |
| 1899 |
if ($code != $tf2Code && $otpstatus == true) { |
| 1900 |
$validation_error->add('tf2Code_error', __('<strong></strong>Doğrulama kodunu yanlış girdiniz!', 'mydomain')); |
| 1901 |
$delete = false; |
| 1902 |
} else { |
| 1903 |
if (isset($netgsm_status) && !empty($netgsm_status) && $netgsm_status == 1 && $control != 0 && $otpstatus ) { |
| 1904 |
// Ayar acikken (sadece telefon iste) ad/soyad sunucu tarafinda da zorunlu degildir |
| 1905 |
if (esc_html(get_option('netgsm_tf2_name_optional')) != 1) { |
| 1906 |
if (isset($first_name) && empty($first_name) || trim($first_name) == '') { |
| 1907 |
$validation_error->add('first_name_error', __('<strong></strong>Adınızı giriniz.', 'mydomain')); |
| 1908 |
$delete = false; |
| 1909 |
} |
| 1910 |
if (isset($last_name) && empty($last_name) || trim($last_name) == '') { |
| 1911 |
$validation_error->add('last_name_error', __('<strong></strong>Soyadınızı giriniz.', 'mydomain')); |
| 1912 |
$delete = false; |
| 1913 |
} |
| 1914 |
} |
| 1915 |
if (isset($billing_phone) && empty($billing_phone) || trim($billing_phone) == '') { |
| 1916 |
$validation_error->add('billing_phone_error', __('<strong></strong>Telefon numaranızı giriniz.', 'mydomain')); |
| 1917 |
$delete = false; |
| 1918 |
} |
| 1919 |
if ($netgsm_phonenumber_zero == 1) { |
| 1920 |
if (substr($billing_phone, 0, 1) != 0) { |
| 1921 |
$validation_error->add('billing_phone_error', __('<strong></strong>Telefon numaranızın başında sıfır olmalıdır.', 'mydomain')); |
| 1922 |
$delete = false; |
| 1923 |
} |
| 1924 |
} |
| 1925 |
|
| 1926 |
date_default_timezone_set('Europe/Istanbul'); |
| 1927 |
$sendTime = get_post_meta(1, $billing_phone . '_2fa_time', true); |
| 1928 |
$sendTime = strtotime($sendTime); |
| 1929 |
$now = time(); |
| 1930 |
$diff = $now - $sendTime; |
| 1931 |
|
| 1932 |
$savedDiff = esc_html(get_option("netgsm_tf2_auth_register_diff")); |
| 1933 |
|
| 1934 |
if ($savedDiff == '' || !is_numeric($savedDiff)) { |
| 1935 |
$savedDiff = 180; |
| 1936 |
} |
| 1937 |
|
| 1938 |
if ($diff > $savedDiff) { |
| 1939 |
$validation_error->add('tf2Code_error', __('<strong></strong>Doğrulama kodunun süresi doldu.Lütfen yeni bir doğrulama şifresi alınız.', 'mydomain')); |
| 1940 |
$delete = false; |
| 1941 |
} |
| 1942 |
} |
| 1943 |
} |
| 1944 |
if ($delete == true) { |
| 1945 |
delete_post_meta(1, $billing_phone . '_2fa', $code); |
| 1946 |
delete_post_meta(1, $billing_phone . '_2fa_time'); |
| 1947 |
delete_post_meta(1, $billing_phone . '_2fa_ref'); |
| 1948 |
} |
| 1949 |
|
| 1950 |
return $validation_error; |
| 1951 |
} |
| 1952 |
|
| 1953 |
add_action('woocommerce_created_customer', 'netgsm_newcustomer', 10, 3); |
| 1954 |
function netgsm_newcustomer($customer_id) |
| 1955 |
{ |
| 1956 |
|
| 1957 |
$newuser1 = esc_html(get_option("netgsm_newuser_to_admin_control")); |
| 1958 |
$newuser2 = esc_html(get_option("netgsm_newuser_to_customer_control")); |
| 1959 |
$newuser3 = esc_html(get_option("netgsm_rehber_control")); |
| 1960 |
$control = netgsm_newcustomer_control(); |
| 1961 |
$billing_phone = ""; |
| 1962 |
$billing_phone = !empty($_POST['billing_phone']) ? sanitize_text_field($_POST['billing_phone']) : '0'; |
| 1963 |
$email = !empty($_POST['email']) ? sanitize_text_field($_POST['email']) : '-'; |
| 1964 |
|
| 1965 |
|
| 1966 |
if (isset($_POST['first_name'])) { |
| 1967 |
$first_name = !empty($_POST['first_name']) ? sanitize_text_field($_POST['first_name']) : '-'; |
| 1968 |
} else { |
| 1969 |
$first_name = !empty($_POST['billing_first_name']) ? sanitize_text_field($_POST['billing_first_name']) : '-'; |
| 1970 |
} |
| 1971 |
|
| 1972 |
if (isset($_POST['last_name'])) { |
| 1973 |
$last_name = !empty($_POST['last_name']) ? sanitize_text_field($_POST['last_name']) : '-'; |
| 1974 |
} else { |
| 1975 |
$last_name = !empty($_POST['billing_last_name']) ? sanitize_text_field($_POST['billing_last_name']) : '-'; |
| 1976 |
} |
| 1977 |
|
| 1978 |
$netgsm_status = esc_html(get_option("netgsm_status")); |
| 1979 |
$replace = new ReplaceFunction(); |
| 1980 |
|
| 1981 |
|
| 1982 |
if (isset($netgsm_status) && !empty($netgsm_status) && $netgsm_status == 1 && $control != 0) { |
| 1983 |
update_user_meta($customer_id, 'billing_phone', $billing_phone); |
| 1984 |
update_user_meta($customer_id, 'first_name', $first_name); |
| 1985 |
update_user_meta($customer_id, 'last_name', $last_name); |
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
if (get_option("netgsm_iys_check_control") == '1') { |
| 1990 |
add_user_meta($customer_id, 'netgsm_kvkk_check', sanitize_text_field($_POST['netgsm_iys'])); |
| 1991 |
|
| 1992 |
if (substr($billing_phone, 0, 1) == "0") { |
| 1993 |
$phone = "+9" . $billing_phone; |
| 1994 |
} else if (substr($billing_phone, 0, 2) == "90") { |
| 1995 |
$phone = "+" . $billing_phone; |
| 1996 |
} else if (substr($billing_phone, 0, 3) == "+90") { |
| 1997 |
$phone = $billing_phone; |
| 1998 |
} else { |
| 1999 |
$phone = "+90" . $billing_phone; |
| 2000 |
} |
| 2001 |
|
| 2002 |
if ($_POST['netgsm_iys'] == 1 && (get_option('netgsm_brandcode_control')) == 1 && (get_option('netgsm_brandcode_text')) != '') { |
| 2003 |
$netgsm = new Netgsmsms(sanitize_text_field(get_option("netgsm_user")), sanitize_text_field(get_option("netgsm_pass"))); |
| 2004 |
$recipient_type = sanitize_text_field(get_option('netgsm_recipient_type')); |
| 2005 |
date_default_timezone_set('Europe/Istanbul'); |
| 2006 |
|
| 2007 |
if (!empty(type_array())) { |
| 2008 |
|
| 2009 |
if (sanitize_text_field(get_option('netgsm_recipient_type')) == "1") { |
| 2010 |
$recipient_type = "BIREYSEL"; |
| 2011 |
$response = $response = $netgsm->iysadd(iys_phonecontrol($billing_phone), $email, date('Y-m-d H:i:s'), sanitize_text_field(get_option('netgsm_brandcode_text')), $recipient_type, type_array()); |
| 2012 |
} else if (sanitize_text_field(get_option('netgsm_recipient_type')) == "2") { |
| 2013 |
$recipient_type = "TACIR"; |
| 2014 |
$response = $response = $netgsm->iysadd(iys_phonecontrol($billing_phone), $email, date('Y-m-d H:i:s'), sanitize_text_field(get_option('netgsm_brandcode_text')), $recipient_type, type_array()); |
| 2015 |
} else { |
| 2016 |
return; |
| 2017 |
} |
| 2018 |
} |
| 2019 |
} |
| 2020 |
} |
| 2021 |
|
| 2022 |
$custom_settings_admin = netgsm_getCustomSetting('netgsm_newuser_to_admin_json', '_timecondition'); |
| 2023 |
$custom_settings_customer = netgsm_getCustomSetting('netgsm_newuser_to_customer_json', '_timecondition'); |
| 2024 |
|
| 2025 |
/*if(empty($first_name)){ |
| 2026 |
update_user_meta($customer_id, 'first_name', sanitize_text_field($_POST['billing_first_name']), ''); |
| 2027 |
} |
| 2028 |
if (empty($last_name)){ |
| 2029 |
update_user_meta($customer_id, 'last_name', sanitize_text_field($_POST['billing_last_name']), ''); |
| 2030 |
}*/ |
| 2031 |
$userinfo = get_userdata($customer_id); |
| 2032 |
if (isset($newuser1) && !empty($newuser1) && $newuser1 == 1) { //admine mesaj |
| 2033 |
$phone = esc_html(get_option('netgsm_newuser_to_admin_no')); |
| 2034 |
$messageContent = sanitize_textarea_field(wp_unslash(get_option('netgsm_newuser_to_admin_text'))); |
| 2035 |
$messageContent = strip_tags($messageContent); |
| 2036 |
$data = array( |
| 2037 |
'first_name' => $first_name, |
| 2038 |
'last_name' => $last_name, |
| 2039 |
'user_login' => $userinfo->user_login, |
| 2040 |
'phone' => $billing_phone, |
| 2041 |
'user_email' => $userinfo->user_email, |
| 2042 |
'message' => $messageContent |
| 2043 |
); |
| 2044 |
$message = $replace->netgsm_replace_newuser_to_text($data); |
| 2045 |
$message = $replace->netgsm_replace_date($message); |
| 2046 |
|
| 2047 |
netgsm_sendSMS_oneToMany($phone, $message, ['startDate' => $custom_settings_admin]); |
| 2048 |
} |
| 2049 |
if (isset($newuser2) && !empty($newuser2) && $newuser2 == 1) { //müşteriye mesaj |
| 2050 |
$messageContent = sanitize_textarea_field(wp_unslash(get_option('netgsm_newuser_to_customer_text'))); |
| 2051 |
$messageContent = strip_tags($messageContent); |
| 2052 |
$data = array( |
| 2053 |
'first_name' => $first_name, |
| 2054 |
'last_name' => $last_name, |
| 2055 |
'user_login' => $userinfo->user_login, |
| 2056 |
'phone' => $billing_phone, |
| 2057 |
'user_email' => $userinfo->user_email, |
| 2058 |
'message' => $messageContent |
| 2059 |
); |
| 2060 |
$message = $replace->netgsm_replace_newuser_to_text($data); |
| 2061 |
$message = $replace->netgsm_replace_date($message); |
| 2062 |
netgsm_sendSMS_oneToMany($billing_phone, $message, ['startDate' => $custom_settings_customer]); |
| 2063 |
} |
| 2064 |
} |
| 2065 |
} |
| 2066 |
|
| 2067 |
add_action('lmfwc_event_post_order_license_keys', 'netgsm_new_licance', 10, 1); |
| 2068 |
function netgsm_new_licance($id) |
| 2069 |
{ |
| 2070 |
$netgsm_status = esc_html(get_option("netgsm_status")); |
| 2071 |
$netgsm_licence_key_to_meta = esc_html(get_option("netgsm_licence_key_to_meta")); |
| 2072 |
if (isset($netgsm_status) && !empty($netgsm_status) && $netgsm_status == 1 && $netgsm_licence_key_to_meta == 1) { |
| 2073 |
$licences = []; |
| 2074 |
foreach ($id['licenses'] as $item) { |
| 2075 |
$licence = apply_filters('lmfwc_decrypt', $item->getLicenseKey()); |
| 2076 |
array_push($licences, $licence); |
| 2077 |
} |
| 2078 |
$keys = implode(' , ', $licences); |
| 2079 |
|
| 2080 |
add_post_meta($id['orderId'], '_licence_keys', $keys, ''); |
| 2081 |
} |
| 2082 |
} |
| 2083 |
|
| 2084 |
//payment_complete ve thankyou kancalarının çalışmaması durumlarında özel kanca çalıştır(ayarlanmalı.) |
| 2085 |
$netgsm_new_order_custom_action = netgsm_getCustomSetting('netgsm_neworder_to_admin_json', '_otherAction'); |
| 2086 |
|
| 2087 |
if ($netgsm_new_order_custom_action != '') { |
| 2088 |
add_action($netgsm_new_order_custom_action, 'netgsm_new_order_custom_action', 10, 3); |
| 2089 |
} else { |
| 2090 |
add_action('woocommerce_payment_complete', 'netgsm_new_order_send_sms', 10, 1); //yeni siparişte sms gönder |
| 2091 |
add_action('woocommerce_thankyou', 'netgsm_new_order_send_sms', 10, 1); //yeni siparişte sms gönder |
| 2092 |
} |
| 2093 |
function netgsm_new_order_custom_action($order_id, $data, $order) |
| 2094 |
{ |
| 2095 |
netgsm_new_order_send_sms($order_id); |
| 2096 |
} |
| 2097 |
|
| 2098 |
add_action('wp_insert_post', 'netgsm_new_order_admin_panel', 10, 1); |
| 2099 |
function netgsm_new_order_admin_panel($post_id) |
| 2100 |
{ |
| 2101 |
if (function_exists('wc_get_order')) { |
| 2102 |
$order = wc_get_order($post_id); |
| 2103 |
if (method_exists((object)$order, 'get_billing_phone') && $order->get_billing_phone() != '') { |
| 2104 |
$custom_settings_admin = netgsm_getCustomSetting('netgsm_neworder_to_admin_json', '_addOrderAdminPanel'); |
| 2105 |
$custom_settings_customer = netgsm_getCustomSetting('netgsm_neworder_to_customer_json', '_addOrderAdminPanel'); |
| 2106 |
if ($custom_settings_admin == 1) { |
| 2107 |
netgsm_new_order_send_sms($post_id, 1); |
| 2108 |
} |
| 2109 |
if ($custom_settings_customer == 1) { |
| 2110 |
netgsm_new_order_send_sms($post_id, 2); |
| 2111 |
} |
| 2112 |
} |
| 2113 |
} |
| 2114 |
} |
| 2115 |
|
| 2116 |
function netgsm_new_order_send_sms($order_id, $adminpanel = 0) |
| 2117 |
{ |
| 2118 |
if (get_post_meta($order_id, '_new_order_netgsm', true) && $adminpanel == 0) { // eğer daha önce bu sipariş zaten oluşmuşsa bu fonksiyon dursun |
| 2119 |
return; // sipariş zaten alınmış. |
| 2120 |
} |
| 2121 |
add_post_meta($order_id, '_new_order_netgsm', 'yes', ''); |
| 2122 |
|
| 2123 |
|
| 2124 |
if (function_exists('wc_get_order')) { |
| 2125 |
$order2 = wc_get_order($order_id); |
| 2126 |
$items = $order2->get_items(); |
| 2127 |
|
| 2128 |
$products_info = ""; |
| 2129 |
$products_info_kdv = ""; |
| 2130 |
$prouducts_name = ""; |
| 2131 |
foreach ($items as $item) { |
| 2132 |
$products_info .= $item->get_name() . "(" . $item->get_subtotal() . 'TLx' . $item->get_quantity() . "), "; |
| 2133 |
} |
| 2134 |
foreach ($items as $item) { |
| 2135 |
if ($item->get_subtotal_tax() == "0") { |
| 2136 |
$products_info_kdv .= $item->get_name() . "(" . $item->get_subtotal() . 'TLx' . $item->get_quantity() . "), "; |
| 2137 |
} else { |
| 2138 |
$products_info_kdv .= $item->get_name() . "(" . $item->get_subtotal() . 'TL+KDV x' . $item->get_quantity() . "), "; |
| 2139 |
} |
| 2140 |
} |
| 2141 |
foreach ($items as $item) { |
| 2142 |
$prouducts_name .= $item->get_name(); |
| 2143 |
} |
| 2144 |
$products_info = rtrim($products_info, ' ,'); |
| 2145 |
$products_info_kdv = rtrim($products_info_kdv, ' ,'); |
| 2146 |
$prouducts_name = rtrim($prouducts_name, ' ,'); |
| 2147 |
} else { |
| 2148 |
$products_info = ""; |
| 2149 |
$prouducts_name = ""; |
| 2150 |
$products_info_kdv = ""; |
| 2151 |
} |
| 2152 |
|
| 2153 |
$neworder1 = esc_html(get_option("netgsm_neworder_to_admin_control")); |
| 2154 |
$neworder2 = esc_html(get_option("netgsm_neworder_to_customer_control")); |
| 2155 |
$control = netgsm_neworder_control(); |
| 2156 |
$netgsm_status = esc_html(get_option("netgsm_status")); |
| 2157 |
$order = new WC_Order($order_id); |
| 2158 |
$order = wc_get_order($order_id); |
| 2159 |
|
| 2160 |
if (class_exists('WooCommerce')) { |
| 2161 |
global $woocommerce; |
| 2162 |
$wc_version = isset($woocommerce->version) ? $woocommerce->version : null; |
| 2163 |
} else { |
| 2164 |
$wc_version = null; |
| 2165 |
} |
| 2166 |
|
| 2167 |
if ($wc_version && version_compare($wc_version, '3.0', '>=')) { |
| 2168 |
$user_id = $order ? $order->get_customer_id() : null; // WooCommerce 3.0 ve sonrası |
| 2169 |
} else { |
| 2170 |
$user_id = $order && property_exists($order, 'customer_id') ? $order->customer_id : null; // WooCommerce 2.x ve öncesi |
| 2171 |
} |
| 2172 |
$userinfo = $user_id ? get_userdata($user_id) : false; |
| 2173 |
|
| 2174 |
if ($userinfo) { |
| 2175 |
$user_login = $userinfo->user_login; |
| 2176 |
} else { |
| 2177 |
$user_login = ''; // Hata olmaması için varsayılan değer atanıyor |
| 2178 |
} |
| 2179 |
$userinfo = get_userdata($user_id); |
| 2180 |
$replace = new ReplaceFunction(); |
| 2181 |
$custom_settings_admin = netgsm_getCustomSetting('netgsm_neworder_to_admin_json', '_timecondition'); |
| 2182 |
$custom_settings_customer = netgsm_getCustomSetting('netgsm_neworder_to_customer_json', '_timecondition'); |
| 2183 |
$custom_settings_customer_private_phone_key = netgsm_getCustomSetting('netgsm_neworder_to_customer_json', '_custom_phone_key'); |
| 2184 |
|
| 2185 |
|
| 2186 |
|
| 2187 |
if (isset($netgsm_status) && !empty($netgsm_status) && $netgsm_status == 1 && $control != 0) { |
| 2188 |
if (isset($neworder1) && !empty($neworder1) && $neworder1 == 1 && (in_array($adminpanel, [0, 1]))) { //admine mesaj |
| 2189 |
$phone = esc_html(get_option('netgsm_neworder_to_admin_no')); |
| 2190 |
$username = explode('@', $order->billing_email); |
| 2191 |
$messageContent = sanitize_textarea_field(wp_unslash(get_option('netgsm_neworder_to_admin_text'))); |
| 2192 |
$messageContent = strip_tags($messageContent); |
| 2193 |
|
| 2194 |
$data = array( |
| 2195 |
'order_id' => $order_id, |
| 2196 |
'total' => $order->total, |
| 2197 |
'first_name' => $order->billing_first_name, |
| 2198 |
'last_name' => $order->billing_last_name, |
| 2199 |
'user_login' => $user_login, |
| 2200 |
'phone' => $order->billing_phone, |
| 2201 |
'user_email' => $order->billing_email, |
| 2202 |
'items' => $products_info, |
| 2203 |
'items_kdv' => $products_info_kdv, |
| 2204 |
'items_name' => $prouducts_name, |
| 2205 |
'message' => $messageContent, |
| 2206 |
); |
| 2207 |
$message = $replace->netgsm_replace_neworder_to_text($data); |
| 2208 |
$message = $replace->netgsm_replace_order_meta_datas($order, $message); |
| 2209 |
$metadatas = get_post_meta($order_id); |
| 2210 |
$message = $replace->netgsm_replace_order_meta_datas2($metadatas, $message); |
| 2211 |
$message = $replace->netgsm_replace_order_add_datas($order, $message, 'data', '[data:'); |
| 2212 |
$message = $replace->netgsm_replace_date($message); |
| 2213 |
netgsm_sendSMS_oneToMany($phone, $message, ['startDate' => $custom_settings_admin]); |
| 2214 |
} |
| 2215 |
|
| 2216 |
if (isset($neworder2) && !empty($neworder2) && $neworder2 == 1 && (in_array($adminpanel, [0, 2]))) { //müşteriye mesaj |
| 2217 |
$order = wc_get_order($order_id); |
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
$phone_key = 'billing_phone'; |
| 2222 |
if ($custom_settings_customer_private_phone_key != '') { |
| 2223 |
$phone_key = $custom_settings_customer_private_phone_key; |
| 2224 |
} |
| 2225 |
$sendsmsphone = ''; |
| 2226 |
if (isset($order->{$phone_key})) { |
| 2227 |
$sendsmsphone = $order->{$phone_key}; |
| 2228 |
} |
| 2229 |
if ($sendsmsphone == '' || !is_numeric($sendsmsphone)) { |
| 2230 |
$sendsmsphone = $order->billing_phone; |
| 2231 |
} |
| 2232 |
$messageContent = sanitize_textarea_field(wp_unslash(get_option('netgsm_neworder_to_customer_text'))); |
| 2233 |
$messageContent = strip_tags($messageContent); |
| 2234 |
$data = array( |
| 2235 |
'order_id' => $order_id, |
| 2236 |
'total' => $order->total, |
| 2237 |
'first_name' => $order->billing_first_name, |
| 2238 |
'last_name' => $order->billing_last_name, |
| 2239 |
'user_login' => $userinfo->user_login, |
| 2240 |
'phone' => $sendsmsphone, |
| 2241 |
'user_email' => $order->billing_email, |
| 2242 |
'items' => $products_info, |
| 2243 |
'items_kdv' => $products_info_kdv, |
| 2244 |
'items_name' => $prouducts_name, |
| 2245 |
'message' => $messageContent |
| 2246 |
); |
| 2247 |
$message = $replace->netgsm_replace_neworder_to_text($data); |
| 2248 |
$message = $replace->netgsm_replace_order_meta_datas($order, $message); |
| 2249 |
$metadatas = get_post_meta($order_id); |
| 2250 |
$message = $replace->netgsm_replace_order_meta_datas2($metadatas, $message); |
| 2251 |
$message = $replace->netgsm_replace_order_add_datas($order, $message, 'data', '[data:'); |
| 2252 |
$message = $replace->netgsm_replace_date($message); |
| 2253 |
netgsm_sendSMS_oneToMany($sendsmsphone, $message, ['startDate' => $custom_settings_customer]); |
| 2254 |
} |
| 2255 |
} |
| 2256 |
} |
| 2257 |
|
| 2258 |
//120--- cancelled--- completed |
| 2259 |
function netgsm_order_status_changed($this_get_id, $this_status_transition_from, $this_status_transition_to, $instance) |
| 2260 |
{ |
| 2261 |
netgsm_order_status_changed_sendSMS($this_get_id, 'netgsm_order_status_text_wc-' . $this_status_transition_to, $this_status_transition_to); |
| 2262 |
}; |
| 2263 |
add_action('woocommerce_order_status_changed', 'netgsm_order_status_changed', 10, 4); |
| 2264 |
|
| 2265 |
add_action('woocommerce_order_status_cancelled', 'netgsm_order_status_cancelled'); |
| 2266 |
function netgsm_order_status_cancelled($order_id) |
| 2267 |
{ |
| 2268 |
$control = esc_html(get_option("netgsm_order_refund_to_admin_control")); |
| 2269 |
$message = sanitize_textarea_field(wp_unslash(get_option('netgsm_order_refund_to_admin_text'))); |
| 2270 |
$message = strip_tags($messageContent); |
| 2271 |
$phones = esc_html(get_option("netgsm_order_refund_to_admin_no")); |
| 2272 |
$netgsm_status = esc_html(get_option("netgsm_status")); |
| 2273 |
$replace = new ReplaceFunction(); |
| 2274 |
if (isset($netgsm_status) && !empty($netgsm_status) && $netgsm_status == 1) { |
| 2275 |
if (isset($control) && !empty($control) && $control == 1) { |
| 2276 |
if (isset($message) && !empty($message)) { |
| 2277 |
$custom_settings_cancelled_timecondition = netgsm_getCustomSetting('netgsm_order_refund_to_admin_json', '_timecondition'); |
| 2278 |
|
| 2279 |
$order = new WC_Order($order_id); |
| 2280 |
$userinfo = get_userdata($order->customer_id); |
| 2281 |
$data = array( |
| 2282 |
'order_id' => $order_id, |
| 2283 |
'first_name' => $userinfo->first_name, |
| 2284 |
'last_name' => $userinfo->last_name, |
| 2285 |
'user_login' => $userinfo->user_login, |
| 2286 |
'phone' => $order->billing_phone, |
| 2287 |
'user_email' => $userinfo->user_email, |
| 2288 |
'message' => $message |
| 2289 |
); |
| 2290 |
$message = $replace->netgsm_replace_order_status_changes($data); |
| 2291 |
$message = $replace->netgsm_replace_order_meta_datas($order, $message); |
| 2292 |
$metadatas = get_post_meta($order_id); |
| 2293 |
$message = $replace->netgsm_replace_order_meta_datas2($metadatas, $message); |
| 2294 |
$message = $replace->netgsm_replace_date($message); |
| 2295 |
netgsm_sendSMS_oneToMany($phones, $message, ['startDate' => $custom_settings_cancelled_timecondition]); |
| 2296 |
} |
| 2297 |
} |
| 2298 |
} |
| 2299 |
// netgsm_order_status_changed_sendSMS($order_id, 'netgsm_order_status_text_wc-cancelled'); |
| 2300 |
} |
| 2301 |
|
| 2302 |
|
| 2303 |
function netgsm_sendSMS_oneToMany($phone, $message, $settings = []) |
| 2304 |
{ |
| 2305 |
$replace = new ReplaceFunction(); |
| 2306 |
$json = array(); |
| 2307 |
if (isset($phone) && isset($message) && !empty($phone) && !empty($message)) { |
| 2308 |
$netgsm = $netgsm = new Netgsmsms(sanitize_text_field(get_option("netgsm_user")), sanitize_text_field(get_option("netgsm_pass")), sanitize_text_field(get_option('netgsm_input_smstitle')), sanitize_text_field(get_option("netgsm_trChar"))); |
| 2309 |
if (isset($settings['startDate']) && $settings['startDate'] != '' && is_numeric(intval($settings['startDate']))) { |
| 2310 |
$netgsm->setStartDate(date('Y-m-d H:i', current_time('timestamp') + ($settings['startDate'] * 60))); |
| 2311 |
} |
| 2312 |
$json = $netgsm->sendSMS($replace->netgsm_spaceTrim($phone), $message); |
| 2313 |
} else { |
| 2314 |
$json['durum'] = '0'; |
| 2315 |
$json['mesaj'] = 'Sms gönderimi başarısız.'; |
| 2316 |
} |
| 2317 |
return json_encode($json); |
| 2318 |
} |
| 2319 |
|
| 2320 |
function netgsm_neworder_control() |
| 2321 |
{ |
| 2322 |
$neworder1 = esc_html(get_option("netgsm_neworder_to_admin_control")); |
| 2323 |
$neworder2 = esc_html(get_option("netgsm_neworder_to_customer_control")); |
| 2324 |
$control = 0; |
| 2325 |
if (isset($neworder1) && !empty($neworder1) && $neworder1 == 1) { |
| 2326 |
$control = 1; |
| 2327 |
} elseif (isset($neworder2) && !empty($neworder2) && $neworder2 == 1) { |
| 2328 |
$control = 2; |
| 2329 |
} |
| 2330 |
return $control; |
| 2331 |
} |
| 2332 |
|
| 2333 |
|
| 2334 |
|
| 2335 |
function netgsm_order_status_changed_sendSMS($order_id, $text, $this_status_transition_to) |
| 2336 |
{ |
| 2337 |
$control = esc_html(get_option("netgsm_orderstatus_change_customer_control")); |
| 2338 |
$message = sanitize_textarea_field(wp_unslash(get_option($text))); |
| 2339 |
$message = strip_tags($message); |
| 2340 |
$netgsm_status = esc_html(get_option("netgsm_status")); |
| 2341 |
$replace = new ReplaceFunction(); |
| 2342 |
|
| 2343 |
|
| 2344 |
if (isset($netgsm_status) && !empty($netgsm_status) && $netgsm_status == 1) { |
| 2345 |
if (isset($control) && !empty($control) && $control == 1) { |
| 2346 |
if (isset($message) && !empty($message)) { |
| 2347 |
$order = new WC_Order($order_id); |
| 2348 |
$orderPrice = $order->get_total(); |
| 2349 |
$userinfo = get_userdata($order->customer_id); |
| 2350 |
// $trackingCode = ''; |
| 2351 |
// $trackingCompany = ''; |
| 2352 |
// $tracking_items = $order->get_meta('_wc_shipment_tracking_items'); |
| 2353 |
// if (!empty($tracking_items) && is_array($tracking_items)) { |
| 2354 |
// foreach ($tracking_items as $item) { |
| 2355 |
// $trackingCompany = $item['tracking_provider']; |
| 2356 |
// $trackingCode = $item['tracking_number']; |
| 2357 |
// } |
| 2358 |
// } |
| 2359 |
// foreach ($order->meta_data as $meta_datum) { |
| 2360 |
// if ($meta_datum->key == 'kargo_takip_no') { |
| 2361 |
// $trackingCode = $meta_datum->value; |
| 2362 |
// } |
| 2363 |
// if ($meta_datum->key == 'kargo_firmasi') { |
| 2364 |
// $trackingCompany = $meta_datum->value; |
| 2365 |
// } |
| 2366 |
// } |
| 2367 |
$trackingCompany = $order->get_meta('tracking_company'); |
| 2368 |
$trackingCode = $order->get_meta('tracking_code'); |
| 2369 |
$trackingCompany = !empty($trackingCompany) ? $trackingCompany : ''; |
| 2370 |
$trackingCode = !empty($trackingCode) ? $trackingCode : ''; |
| 2371 |
if ((isset($userinfo->user_login) && $userinfo->user_login != '')) { |
| 2372 |
$user_login = $userinfo->user_login; |
| 2373 |
} else if(!empty($order->shipping_first_name)) { |
| 2374 |
$user_login = $order->shipping_first_name . ' '. $order->shipping_last_name; |
| 2375 |
} else { |
| 2376 |
$user_login = $order->billing_first_name . ' ' . $order->billing_last_name; |
| 2377 |
} |
| 2378 |
|
| 2379 |
|
| 2380 |
$custom_settings_changed_timecondition = netgsm_getCustomSetting('netgsm_order_status_text_wc-' . $this_status_transition_to . '_json', '_timecondition'); |
| 2381 |
$custom_settings_customer_private_phone_key = netgsm_getCustomSetting('netgsm_order_status_text_wc-' . $this_status_transition_to . '_json', '_custom_phone_key'); |
| 2382 |
|
| 2383 |
$phone_key = 'billing_phone'; |
| 2384 |
if ($custom_settings_customer_private_phone_key != '') { |
| 2385 |
$phone_key = $custom_settings_customer_private_phone_key; |
| 2386 |
} |
| 2387 |
$sendsmsphone = ''; |
| 2388 |
if (isset($order->{$phone_key})) { |
| 2389 |
$sendsmsphone = $order->{$phone_key}; |
| 2390 |
} |
| 2391 |
if ($sendsmsphone == '' || !is_numeric($sendsmsphone)) { |
| 2392 |
$sendsmsphone = $order->billing_phone; |
| 2393 |
} |
| 2394 |
|
| 2395 |
$data = array( |
| 2396 |
'order_id' => $order_id, |
| 2397 |
|
| 2398 |
'first_name' => !empty($order->shipping_first_name) ? $order->shipping_first_name : $order->billing_first_name, |
| 2399 |
'last_name' => !empty($order->shipping_last_name) ? $order->shipping_last_name : $order->billing_last_name, |
| 2400 |
'user_login' => $user_login, |
| 2401 |
'phone' => $sendsmsphone, |
| 2402 |
'user_email' => $order->billing_email, |
| 2403 |
'message' => $message, |
| 2404 |
'siparis_tutar' => $orderPrice, |
| 2405 |
'trackingCompany' => $replace->netgsm_replace_shipping_company($trackingCompany), |
| 2406 |
'trackingCode' => $trackingCode |
| 2407 |
); |
| 2408 |
$message = $replace->netgsm_replace_order_status_changes($data); |
| 2409 |
$message = $replace->netgsm_replace_order_meta_datas($order, $message); |
| 2410 |
$metadatas = get_post_meta($order_id); |
| 2411 |
$message = $replace->netgsm_replace_order_meta_datas2($metadatas, $message); |
| 2412 |
$message = $replace->netgsm_replace_order_add_datas($order, $message, 'data', '[data:'); |
| 2413 |
$message = $replace->netgsm_replace_date($message); |
| 2414 |
netgsm_sendSMS_oneToMany($sendsmsphone, $message, ['startDate' => $custom_settings_changed_timecondition]); |
| 2415 |
} |
| 2416 |
} |
| 2417 |
} |
| 2418 |
} |
| 2419 |
|
| 2420 |
add_action('woocommerce_new_order_note_data', 'netgsm_new_order_note_data', 10, 2); |
| 2421 |
function netgsm_new_order_note_data($args, $args2) |
| 2422 |
{ |
| 2423 |
//type 0 == note1 = Özel Not -- netgsm_newnote1_to_customer_control -- netgsm_newnote1_to_customer_text |
| 2424 |
//type 1 == note2 = Müşteriye not -- |
| 2425 |
|
| 2426 |
$order_id = $args['comment_post_ID']; |
| 2427 |
$type = $args2['is_customer_note']; |
| 2428 |
|
| 2429 |
$note = $args['comment_content']; |
| 2430 |
|
| 2431 |
$status_note1 = esc_html(get_option("netgsm_newnote1_to_customer_control")); |
| 2432 |
$status_note2 = esc_html(get_option("netgsm_newnote2_to_customer_control")); |
| 2433 |
|
| 2434 |
if (!empty($status_note1) && $status_note1 == 1 && $type == 0) { //özel sms |
| 2435 |
$customermessage = esc_html(get_option("netgsm_newnote1_to_customer_text")); |
| 2436 |
$options = 'netgsm_newnote1_to_customer_json'; |
| 2437 |
netgsm_new_order_note_sendSMS($order_id, $type, $note, $customermessage, $options); |
| 2438 |
} |
| 2439 |
|
| 2440 |
if (!empty($status_note2) && $status_note2 == 1 && $type == 1) { //müşteriye sms |
| 2441 |
$customermessage = esc_html(get_option("netgsm_newnote2_to_customer_text")); |
| 2442 |
$options = 'netgsm_newnote2_to_customer_json'; |
| 2443 |
netgsm_new_order_note_sendSMS($order_id, $type, $note, $customermessage, $options); |
| 2444 |
} |
| 2445 |
return $args; |
| 2446 |
} |
| 2447 |
|
| 2448 |
|
| 2449 |
function netgsm_new_order_note_sendSMS($order_id, $note_type, $note, $customermessage, $optionskey) |
| 2450 |
{ |
| 2451 |
$netgsm_status = esc_html(get_option("netgsm_status")); |
| 2452 |
$replace = new ReplaceFunction(); |
| 2453 |
if (isset($netgsm_status) && !empty($netgsm_status) && $netgsm_status == 1) { |
| 2454 |
if (isset($customermessage) && !empty($customermessage)) { |
| 2455 |
$customermessage = sanitize_textarea_field(wp_unslash($customermessage)); |
| 2456 |
$customermessage = strip_tags($customermessage); |
| 2457 |
$order = new WC_Order($order_id); |
| 2458 |
$userinfo = get_userdata($order->customer_id); |
| 2459 |
|
| 2460 |
if ((isset($userinfo->user_login) && $userinfo->user_login != '')) { |
| 2461 |
$user_login = $userinfo->user_login; |
| 2462 |
} else { |
| 2463 |
$user_login = $order->shipping_first_name . $order->shipping_last_name; |
| 2464 |
} |
| 2465 |
|
| 2466 |
$custom_settings_changed_timecondition = netgsm_getCustomSetting($optionskey, '_timecondition'); |
| 2467 |
$custom_settings_customer_private_phone_key = netgsm_getCustomSetting($optionskey, '_custom_phone_key'); |
| 2468 |
|
| 2469 |
$phone_key = 'billing_phone'; |
| 2470 |
if ($custom_settings_customer_private_phone_key != '') { |
| 2471 |
$phone_key = $custom_settings_customer_private_phone_key; |
| 2472 |
} |
| 2473 |
$sendsmsphone = ''; |
| 2474 |
if (isset($order->{$phone_key})) { |
| 2475 |
$sendsmsphone = $order->{$phone_key}; |
| 2476 |
} |
| 2477 |
if ($sendsmsphone == '' || !is_numeric($sendsmsphone)) { |
| 2478 |
$sendsmsphone = $order->billing_phone; |
| 2479 |
} |
| 2480 |
|
| 2481 |
$data = array( |
| 2482 |
'order_id' => $order_id, |
| 2483 |
'first_name' => $order->billing_first_name, |
| 2484 |
'last_name' => $order->billing_last_name, |
| 2485 |
'user_login' => $user_login, |
| 2486 |
'phone' => $sendsmsphone, |
| 2487 |
'user_email' => $order->billing_email, |
| 2488 |
'note' => $note, |
| 2489 |
'message' => $customermessage, |
| 2490 |
'total' => $order->total |
| 2491 |
); |
| 2492 |
$message = $replace->netgsm_replace_add_note($data); |
| 2493 |
$message = $replace->netgsm_replace_date($message); |
| 2494 |
netgsm_sendSMS_oneToMany($sendsmsphone, $message, ['startDate' => $custom_settings_changed_timecondition]); |
| 2495 |
} |
| 2496 |
} |
| 2497 |
} |
| 2498 |
|
| 2499 |
function netgsm_yaz($data, $file = 'cf7dosya1.txt') |
| 2500 |
{ |
| 2501 |
touch($file); |
| 2502 |
$dosya = fopen($file, 'w'); |
| 2503 |
fwrite($dosya, print_r($data, TRUE)); |
| 2504 |
fclose($dosya); |
| 2505 |
} |
| 2506 |
|
| 2507 |
/* |
| 2508 |
|
| 2509 |
// WAITLIST STOK İŞLEMLERİ START |
| 2510 |
|
| 2511 |
|
| 2512 |
// Normal ürünlerin stok değişimini dinleyerek stoğa girmesi durumunda waitlist listesine SMS gönderir. |
| 2513 |
|
| 2514 |
function netgsm_product_set_stock($product) |
| 2515 |
{ |
| 2516 |
netgsm_set_stock_trigger($product); |
| 2517 |
}; |
| 2518 |
add_action('woocommerce_product_set_stock', 'netgsm_product_set_stock', 10, 1); |
| 2519 |
|
| 2520 |
|
| 2521 |
// Varyasyonlu ürünlerin stok değişimini dinleyerek stoğa girmesi durumunda waitlist listesine SMS gönderir. |
| 2522 |
|
| 2523 |
function netgsm_product_set_stock_variation($product) |
| 2524 |
{ |
| 2525 |
netgsm_set_stock_trigger($product); |
| 2526 |
} |
| 2527 |
add_action('woocommerce_variation_set_stock', 'netgsm_product_set_stock_variation', 10, 1); |
| 2528 |
|
| 2529 |
|
| 2530 |
// Stok değişikliğini dinleyerek bekleme listesine sms gönderimini tetikleyecek fonksiyon |
| 2531 |
|
| 2532 |
function netgsm_set_stock_trigger($product) |
| 2533 |
{ |
| 2534 |
$productId = $product->get_data()['id']; |
| 2535 |
// $limit = wc_get_low_stock_amount( $product ); |
| 2536 |
// $new_stock = $product->get_changes()['stock_quantity']; |
| 2537 |
// $old_stock = $product->get_data()['stock_quantity']; |
| 2538 |
|
| 2539 |
if (isset($product->get_changes()['stock_status']) && $product->get_changes()['stock_status'] == 'instock') { |
| 2540 |
if (class_exists('Pie_WCWL_Waitlist')) { |
| 2541 |
$waitlist = new Pie_WCWL_Waitlist($product); |
| 2542 |
$users = $waitlist->waitlist; |
| 2543 |
foreach ($users as $customerId => $date) { |
| 2544 |
netgsm_waitlist_send_sms($customerId, $productId); |
| 2545 |
} |
| 2546 |
} |
| 2547 |
} |
| 2548 |
} |
| 2549 |
|
| 2550 |
|
| 2551 |
// waitlist listesine mail gönderildiğinde SMS de gönderir. |
| 2552 |
|
| 2553 |
function netgsm_waitlist_push($customerId, $productId) |
| 2554 |
{ |
| 2555 |
netgsm_waitlist_send_sms($customerId, $productId); |
| 2556 |
} |
| 2557 |
add_action('wcwl_mailout_send_email', 'netgsm_waitlist_push', 10, 2); |
| 2558 |
|
| 2559 |
|
| 2560 |
// Bekleme listelerine SMS gönderimi sağlayan fonksiyondur. |
| 2561 |
|
| 2562 |
function netgsm_waitlist_send_sms($customerId, $productId) |
| 2563 |
{ |
| 2564 |
$control = esc_html(get_option("netgsm_product_waitlist1_control")); |
| 2565 |
$message = esc_html(get_option("netgsm_product_waitlist1_text"));; |
| 2566 |
$netgsm_status = esc_html(get_option("netgsm_status")); |
| 2567 |
$replace = new ReplaceFunction(); |
| 2568 |
$product = wc_get_product($productId); |
| 2569 |
if (isset($netgsm_status) && !empty($netgsm_status) && $netgsm_status == 1) { |
| 2570 |
if (isset($control) && !empty($control) && $control == 1) { |
| 2571 |
if (isset($message) && !empty($message)) { |
| 2572 |
$customer = new WC_Customer($customerId); |
| 2573 |
$product = wc_get_product($productId); |
| 2574 |
|
| 2575 |
|
| 2576 |
$custom_settings_changed_timecondition = netgsm_getCustomSetting('netgsm_product_waitlist1_json', '_timecondition'); |
| 2577 |
$custom_settings_customer_private_phone_key = netgsm_getCustomSetting('netgsm_product_waitlist1_json', '_custom_phone_key'); |
| 2578 |
|
| 2579 |
$phone_key = 'billing_phone'; |
| 2580 |
if ($custom_settings_customer_private_phone_key != '') { |
| 2581 |
$phone_key = $custom_settings_customer_private_phone_key; |
| 2582 |
} |
| 2583 |
|
| 2584 |
$sendsmsphone = ''; |
| 2585 |
if ($customer->{$phone_key} != '') { |
| 2586 |
$sendsmsphone = $customer->{$phone_key}; |
| 2587 |
} |
| 2588 |
|
| 2589 |
if ($sendsmsphone == '' || !is_numeric($sendsmsphone)) { |
| 2590 |
$sendsmsphone = $customer->billing_phone; |
| 2591 |
} |
| 2592 |
|
| 2593 |
$newVar = []; |
| 2594 |
$oldVar = []; |
| 2595 |
array_push($oldVar, '[uye_adi]'); |
| 2596 |
array_push($oldVar, '[uye_soyadi]'); |
| 2597 |
array_push($oldVar, '[uye_telefonu]'); |
| 2598 |
array_push($oldVar, '[uye_epostasi]'); |
| 2599 |
array_push($oldVar, '[kullanici_adi]'); |
| 2600 |
array_push($oldVar, '[urun_kodu]'); |
| 2601 |
array_push($oldVar, '[urun_adi]'); |
| 2602 |
array_push($oldVar, '[stok_miktari]'); |
| 2603 |
|
| 2604 |
$newVar['uye_adi'] = sanitize_text_field($customer->first_name); |
| 2605 |
$newVar['uye_soyadi'] = sanitize_text_field($customer->last_name); |
| 2606 |
$newVar['uye_telefonu'] = sanitize_text_field($customer->billing_phone); |
| 2607 |
$newVar['uye_epostasi'] = sanitize_text_field($customer->email); |
| 2608 |
$newVar['kullanici_adi'] = sanitize_text_field($customer->display_name); |
| 2609 |
$newVar['urun_kodu'] = sanitize_text_field($product->sku); |
| 2610 |
$newVar['urun_adi'] = sanitize_text_field($product->name); |
| 2611 |
$newVar['stok_miktari'] = sanitize_text_field($product->stock); |
| 2612 |
|
| 2613 |
$message = $replace->netgsm_replace_array($oldVar, $newVar, $message); |
| 2614 |
|
| 2615 |
$message = $replace->netgsm_meta_data_replace($customer->data, $message, '[meta_user:'); |
| 2616 |
$message = $replace->netgsm_meta_data_replace($product->get_data(), $message, '[meta_product:'); |
| 2617 |
$message = $replace->netgsm_replace_date($message); |
| 2618 |
netgsm_sendSMS_oneToMany($sendsmsphone, $message, ['startDate' => $custom_settings_changed_timecondition]); |
| 2619 |
} |
| 2620 |
} |
| 2621 |
} |
| 2622 |
} |
| 2623 |
|
| 2624 |
|
| 2625 |
// WAITLIST STOK İŞLEMLERİ END |
| 2626 |
|
| 2627 |
*/ |
| 2628 |
//contact form 7 açık seçeneklerin smsleri gönderilir. sadece başarılı yanıt aldığında gönderiyor. |
| 2629 |
add_action('wpcf7_mail_sent', 'netgsm_cf7_form_submit', 10, 1); |
| 2630 |
function netgsm_cf7_form_submit($contact_form) |
| 2631 |
{ |
| 2632 |
$title = $contact_form->title; |
| 2633 |
$submission = WPCF7_Submission::get_instance(); |
| 2634 |
$phone_customer = ''; |
| 2635 |
$phone_admin = esc_html(get_option('netgsm_cf7_to_admin_no')); |
| 2636 |
|
| 2637 |
if ($submission) { |
| 2638 |
$posted_data = $submission->get_posted_data(); |
| 2639 |
} |
| 2640 |
$form_id = 0; |
| 2641 |
if (isset($posted_data['_wpcf7']) && $posted_data['_wpcf7'] > 0) { |
| 2642 |
$form_id = $posted_data['_wpcf7']; |
| 2643 |
} else { |
| 2644 |
$form_id = $contact_form->id; |
| 2645 |
} |
| 2646 |
|
| 2647 |
$netgsm_status = esc_html(get_option("netgsm_status")); |
| 2648 |
if (isset($netgsm_status) && !empty($netgsm_status) && $netgsm_status == 1) { |
| 2649 |
if (isset($posted_data)) { |
| 2650 |
$customer_control = esc_html(get_option('netgsm_cf7_success_customer_control')); |
| 2651 |
if (isset($customer_control) && !empty($customer_control) && $customer_control == 1) { |
| 2652 |
$customer_message = (sanitize_text_field(get_option('netgsm_cf7_list_text_success_customer_' . $form_id))); |
| 2653 |
$phone_customer = $posted_data['telephone']; |
| 2654 |
if ($phone_customer != '') { |
| 2655 |
if ($customer_message != '') { |
| 2656 |
$replace = new ReplaceFunction(); |
| 2657 |
$message = $replace->netgsm_cf7_replace_all_var($posted_data, $customer_message); |
| 2658 |
$message = $replace->netgsm_replace_date($message); |
| 2659 |
$message = sanitize_textarea_field(wp_unslash($message)); |
| 2660 |
$message = strip_tags($message); |
| 2661 |
netgsm_sendSMS_oneToMany($phone_customer, $message); |
| 2662 |
} |
| 2663 |
} |
| 2664 |
} |
| 2665 |
$admin_control = esc_html(get_option('netgsm_cf7_success_admin_control')); |
| 2666 |
if (isset($admin_control) && !empty($admin_control) && $admin_control == 1) { |
| 2667 |
$admin_message = sanitize_text_field(get_option('netgsm_cf7_list_text_success_admin_' . $form_id)); |
| 2668 |
if ($admin_message != '') { |
| 2669 |
$replace = new ReplaceFunction(); |
| 2670 |
$message = $replace->netgsm_cf7_replace_all_var($posted_data, $admin_message); |
| 2671 |
$message = $replace->netgsm_replace_date($message); |
| 2672 |
$message = sanitize_textarea_field(wp_unslash($message)); |
| 2673 |
$message = strip_tags($message); |
| 2674 |
netgsm_sendSMS_oneToMany($phone_admin, $message); |
| 2675 |
} |
| 2676 |
} |
| 2677 |
} |
| 2678 |
} |
| 2679 |
// die; |
| 2680 |
return $posted_data; |
| 2681 |
} |
| 2682 |
|
| 2683 |
/* |
| 2684 |
* WC API için gerekli işlemler |
| 2685 |
*/ |
| 2686 |
add_filter('woocommerce_rest_api_get_rest_namespaces', 'woo_custom_api'); |
| 2687 |
function woo_custom_api($controllers) |
| 2688 |
{ |
| 2689 |
$controllers['wc/v3']['custom'] = 'WC_REST_Custom_Controller'; |
| 2690 |
$controllers['wc/v3']['test'] = 'WC_REST_Custom_Controller'; |
| 2691 |
|
| 2692 |
return $controllers; |
| 2693 |
} |
| 2694 |
|
| 2695 |
|
| 2696 |
function type_array() |
| 2697 |
{ |
| 2698 |
|
| 2699 |
$iys_type = array(); |
| 2700 |
if (esc_html(get_option('netgsm_message')) == 1) { |
| 2701 |
array_push($iys_type, "MESAJ"); |
| 2702 |
} |
| 2703 |
if (sanitize_text_field(get_option('netgsm_call')) == '1') { |
| 2704 |
array_push($iys_type, "ARAMA"); |
| 2705 |
} |
| 2706 |
if (sanitize_text_field(get_option('netgsm_email')) == '1') { |
| 2707 |
array_push($iys_type, "EPOSTA"); |
| 2708 |
} |
| 2709 |
return $iys_type; |
| 2710 |
} |
| 2711 |
|
| 2712 |
function iys_phonecontrol($phone) |
| 2713 |
{ |
| 2714 |
if (substr($phone, 0, 1) == "0") { |
| 2715 |
$phone_edit = "+9" . $phone; |
| 2716 |
} else if (substr($phone, 0, 2) == "90") { |
| 2717 |
$phone_edit = "+" . $phone; |
| 2718 |
} else if (substr($phone, 0, 3) == "+90") { |
| 2719 |
$phone_edit = $phone; |
| 2720 |
} else { |
| 2721 |
$phone_edit = "+90" . $phone; |
| 2722 |
} |
| 2723 |
return $phone_edit; |
| 2724 |
} |
| 2725 |
|
| 2726 |
add_action('wp_footer', 'netgsm_connection_button'); |
| 2727 |
function netgsm_connection_button() |
| 2728 |
{ |
| 2729 |
if (sanitize_text_field(get_option('netgsm_tf2_cash_on_delivery_control')) == '1') { |
| 2730 |
// Block checkout tespiti: checkout sayfasındaki blok türüne bak |
| 2731 |
$checkout_page_id = wc_get_page_id('checkout'); |
| 2732 |
$checkout_post = get_post($checkout_page_id); |
| 2733 |
$is_block_checkout = $checkout_post && has_block('woocommerce/checkout', $checkout_post); |
| 2734 |
if ($is_block_checkout) { |
| 2735 |
// Block checkout için #cod-otp-area ve sendtf2CodeCod burada render edilir |
| 2736 |
?> |
| 2737 |
<div id="cod-otp-area" style="display:none; margin-top:15px;"> |
| 2738 |
<p> |
| 2739 |
<input type="button" class="input-text button wc-block-components-button" value="OTP Gönder" style="width:100%;" onclick="sendtf2CodeCod()"/> |
| 2740 |
</p> |
| 2741 |
<p> |
| 2742 |
<input type="text" name="cod_otp" id="cod_otp" placeholder="OTP Kodunu Giriniz" class="input-text" style="width:100%;"/> |
| 2743 |
</p> |
| 2744 |
</div> |
| 2745 |
<script> |
| 2746 |
if (typeof sendtf2CodeCod === 'undefined') { |
| 2747 |
function sendtf2CodeCod() { |
| 2748 |
var firstname = jQuery('#billing_first_name, #billing-first_name').first().val() || ''; |
| 2749 |
var lastname = jQuery('#billing_last_name, #billing-last_name').first().val() || ''; |
| 2750 |
var phone = jQuery('#billing_phone, #billing-phone').first().val() || ''; |
| 2751 |
var email = jQuery("input[name*='billing_email'], #billing-email").first().val() || ''; |
| 2752 |
|
| 2753 |
var error = ''; |
| 2754 |
if (!firstname) error += '> İsim girilmedi.\n'; |
| 2755 |
if (!lastname) error += '> Soyisim girilmedi.\n'; |
| 2756 |
if (!email) error += '> E-mail adresi girilmedi.\n'; |
| 2757 |
if (!phone) error += '> Telefon numarası girilmedi.\n'; |
| 2758 |
<?php if (sanitize_text_field(get_option('netgsm_tf2_cash_on_delivery_control')) == '1'): ?> |
| 2759 |
if (phone && phone.slice(0, 1) !== '0') error += '> Telefon numarası 0 ile başlamalıdır.\n'; |
| 2760 |
<?php endif; ?> |
| 2761 |
if (error) { alert('Aşağıdaki hatalar alındı : \n\n' + error); return false; } |
| 2762 |
|
| 2763 |
jQuery.post(<?php echo json_encode(admin_url('admin-ajax.php')); ?>, { |
| 2764 |
action: 'netgsm_sendtf2SMS', type: 'cod', |
| 2765 |
phone: phone, first_name: firstname, last_name: lastname, email: email |
| 2766 |
}, function (response) { |
| 2767 |
var endChar = response.substring(response.length - 1); |
| 2768 |
if (endChar === '0') response = response.substring(0, response.length - 1); |
| 2769 |
var obje = JSON.parse(response); |
| 2770 |
if (obje.status === 'success') { |
| 2771 |
alert('Lütfen ' + obje.phone + ' numaralı telefonunuza gelen güvenlik kodunu giriniz.'); |
| 2772 |
} else { |
| 2773 |
alert(obje.data || 'Bilinmeyen bir hata oluştu. GSM numarası girdiğinize emin olun.'); |
| 2774 |
} |
| 2775 |
}); |
| 2776 |
} |
| 2777 |
} |
| 2778 |
|
| 2779 |
// Block checkout: cod_otp input değerini registered field ile senkronize et |
| 2780 |
jQuery(document).on('input', '#cod_otp', function () { |
| 2781 |
var val = jQuery(this).val(); |
| 2782 |
jQuery('input[id*="cod_otp"][id*="netgsm"], input[name*="netgsm/cod_otp"]').val(val); |
| 2783 |
}); |
| 2784 |
</script> |
| 2785 |
<?php |
| 2786 |
} |
| 2787 |
?> |
| 2788 |
<script> |
| 2789 |
jQuery(function ($) { |
| 2790 |
var isBlockCheckout = !!document.querySelector('.wp-block-woocommerce-checkout, [data-block-name="woocommerce/checkout"]'); |
| 2791 |
|
| 2792 |
function getActivePaymentMethod() { |
| 2793 |
// 1. Classic Checkout |
| 2794 |
var classic = document.querySelector('input[name="payment_method"]:checked'); |
| 2795 |
if (classic) return classic.value; |
| 2796 |
|
| 2797 |
// 2. Block Checkout: wp.data store (en güvenilir yöntem) |
| 2798 |
if (typeof wp !== 'undefined' && wp.data) { |
| 2799 |
try { |
| 2800 |
var store = wp.data.select('wc/store/payment'); |
| 2801 |
if (store && store.getActivePaymentMethod) return store.getActivePaymentMethod(); |
| 2802 |
} catch (e) {} |
| 2803 |
} |
| 2804 |
|
| 2805 |
// 3. Block Checkout: DOM fallback |
| 2806 |
var blockRadio = document.querySelector( |
| 2807 |
'.wc-block-components-radio-control__option input[type="radio"]:checked,' + |
| 2808 |
'.wc-block-components-payment-method-options input[type="radio"]:checked' |
| 2809 |
); |
| 2810 |
if (blockRadio) return blockRadio.value; |
| 2811 |
|
| 2812 |
return null; |
| 2813 |
} |
| 2814 |
|
| 2815 |
function positionOtpAreaForBlocks() { |
| 2816 |
var area = document.getElementById('cod-otp-area'); |
| 2817 |
if (!area) return; |
| 2818 |
var placeOrder = document.querySelector( |
| 2819 |
'.wc-block-components-checkout-place-order-button,' + |
| 2820 |
'.wp-block-woocommerce-checkout-actions-block,' + |
| 2821 |
'.wc-block-checkout__actions_row' |
| 2822 |
); |
| 2823 |
if (placeOrder && placeOrder.parentNode && !placeOrder.parentNode.contains(area)) { |
| 2824 |
placeOrder.parentNode.insertBefore(area, placeOrder); |
| 2825 |
} |
| 2826 |
injectBlockOtpButton(); |
| 2827 |
} |
| 2828 |
|
| 2829 |
function injectBlockOtpButton() { |
| 2830 |
// Registered netgsm/cod_otp field'ının yanına "OTP Gönder" butonu ekle |
| 2831 |
var otpInput = document.querySelector('input[id*="cod_otp"][id*="netgsm"], input[name="netgsm/cod_otp"]'); |
| 2832 |
if (!otpInput || otpInput.getAttribute('data-netgsm-btn')) return; |
| 2833 |
otpInput.setAttribute('data-netgsm-btn', '1'); |
| 2834 |
var wrapper = otpInput.closest('.wc-block-components-text-input, .wc-block-additional-field, p'); |
| 2835 |
if (wrapper && wrapper.parentNode) { |
| 2836 |
var btn = document.createElement('p'); |
| 2837 |
btn.style.marginBottom = '10px'; |
| 2838 |
btn.innerHTML = '<input type="button" class="input-text button" value="OTP Gönder" style="width:100%;" onclick="sendtf2CodeCod()"/>'; |
| 2839 |
wrapper.parentNode.insertBefore(btn, wrapper); |
| 2840 |
} |
| 2841 |
} |
| 2842 |
|
| 2843 |
function toggleOtpArea() { |
| 2844 |
var method = getActivePaymentMethod(); |
| 2845 |
var area = document.getElementById('cod-otp-area'); |
| 2846 |
if (!area) return; |
| 2847 |
|
| 2848 |
if (method === 'cod') { |
| 2849 |
if (isBlockCheckout) positionOtpAreaForBlocks(); |
| 2850 |
$(area).slideDown(); |
| 2851 |
} else { |
| 2852 |
$(area).slideUp(); |
| 2853 |
var inp = document.getElementById('cod_otp'); |
| 2854 |
if (inp) inp.value = ''; |
| 2855 |
} |
| 2856 |
} |
| 2857 |
|
| 2858 |
// Classic Checkout events |
| 2859 |
$(document.body).on('updated_checkout', toggleOtpArea); |
| 2860 |
$(document).on('change', 'input[name="payment_method"]', toggleOtpArea); |
| 2861 |
|
| 2862 |
// Block Checkout: wp.data store subscription |
| 2863 |
if (typeof wp !== 'undefined' && wp.data) { |
| 2864 |
try { wp.data.subscribe(function () { toggleOtpArea(); }); } catch (e) {} |
| 2865 |
} |
| 2866 |
|
| 2867 |
// Block Checkout: DOM radio change fallback |
| 2868 |
$(document).on('change', '.wc-block-components-radio-control__option input[type="radio"]', toggleOtpArea); |
| 2869 |
|
| 2870 |
// MutationObserver: custom classic checkout temaları için |
| 2871 |
if (!isBlockCheckout) { |
| 2872 |
var paymentEl = document.querySelector('#payment') || document.body; |
| 2873 |
new MutationObserver(function () { toggleOtpArea(); }).observe(paymentEl, { |
| 2874 |
childList: true, subtree: true, attributes: true, |
| 2875 |
attributeFilter: ['checked', 'class'] |
| 2876 |
}); |
| 2877 |
} |
| 2878 |
|
| 2879 |
// Fallback timeout'ları (yavaş tema/AJAX içerikleri için) |
| 2880 |
[500, 1500, 3000].forEach(function (ms) { setTimeout(toggleOtpArea, ms); }); |
| 2881 |
}); |
| 2882 |
</script> |
| 2883 |
<?php |
| 2884 |
} |
| 2885 |
if (get_option('netgsm_asistan') == '1') { |
| 2886 |
$plugin_url = plugin_dir_url(__FILE__); |
| 2887 |
wp_enqueue_style('style1', $plugin_url . 'lib/css/style.css'); |
| 2888 |
wp_enqueue_style('font-awesome', $plugin_url . 'lib/fonts/css/font-awesome.min.css'); |
| 2889 |
wp_enqueue_style('all', $plugin_url . 'lib/fonts/fonts/all.css'); |
| 2890 |
|
| 2891 |
if (sanitize_text_field(get_option('netgsm_asistan_netasistan')) == '1') { |
| 2892 |
|
| 2893 |
echo '<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet"> |
| 2894 |
<label for="connect-menu" class="netasistan-logo"><img id="netasistan-altlogo" src="' . esc_url(plugins_url("netgsm/lib/image/netasistan-alt-logo.svg", dirname(__FILE__))) . '"> |
| 2895 |
</label><input type="checkbox" id="connect-menu" checked="false"/>'; |
| 2896 |
} |
| 2897 |
echo ' |
| 2898 |
<div id="connection-form"> |
| 2899 |
<div class="portal-table"> |
| 2900 |
<div class="netasistan-header" align="left"> |
| 2901 |
<img class="netasistan-headerlogo" src="<?php echo esc_url(plugins_url("netgsm/lib/image/netasistan-header-logo.svg", dirname(__FILE__))); ?>"> |
| 2902 |
<p class="netasistan-headertype">Yardım merkezine hoşgeldiniz.</p> |
| 2903 |
<i class="fa fa-times closeicon" id="connect-close"></i> |
| 2904 |
</div> |
| 2905 |
</div> |
| 2906 |
</div> |
| 2907 |
|
| 2908 |
|
| 2909 |
<div class="netasistan_itemContent" id="netasistan-buttons">'; |
| 2910 |
|
| 2911 |
if (sanitize_text_field(get_option('netgsm_asistan_message')) == '1') { |
| 2912 |
echo '<div class="btnItem" onclick="location.href=\'sms:' . esc_attr(get_option("netgsm_asistan_messagenumber")) . '\'"> |
| 2913 |
<h6><i class="far fa-comment-alt squareIcon mesajBg"></i>Mesaj gönderin</h6> |
| 2914 |
</div>'; |
| 2915 |
} |
| 2916 |
if (sanitize_text_field(get_option('netgsm_asistan_call')) == '1') { |
| 2917 |
echo '<div class="btnItem" onclick="location.href=\'tel:' . esc_attr(get_option("netgsm_asistan_callnumber")) . '\'"> |
| 2918 |
<h6><i class="fas fa-mobile-alt squareIcon aramaBg"></i> Çağrı merkezimizi arayın</h6> |
| 2919 |
</div>'; |
| 2920 |
} |
| 2921 |
if (sanitize_text_field(get_option('netgsm_asistan_email')) == '1') { |
| 2922 |
echo '<div class="btnItem" onclick="location.href=\'mailto:' . esc_attr(get_option('netgsm_asistan_emailaddress')) . '\'"> |
| 2923 |
<h6><i class="far fa-envelope-open squareIcon epostaBg"></i> E-posta gönderin </h6> |
| 2924 |
</div>'; |
| 2925 |
} |
| 2926 |
if (sanitize_text_field(get_option('netgsm_asistan_whatsapp')) == '1') { |
| 2927 |
echo '<div class="btnItem" onclick="location.href=\'https://wa.me/' . esc_attr(get_option("netgsm_asistan_whatsappnumber")) . '\'"> |
| 2928 |
<h6><i class="fab fa-whatsapp squareIcon whatsappBg"></i> WhatsApp</h6> |
| 2929 |
</div>'; |
| 2930 |
} |
| 2931 |
|
| 2932 |
if (sanitize_text_field(get_option('netgsm_asistan_netasistan')) == '1') { |
| 2933 |
$customer = WC()->session->get('customer'); |
| 2934 |
$customerx = new WC_Customer($customer['id']); |
| 2935 |
$phone = netasistan_phonecontrol($customerx->billing['phone']); |
| 2936 |
|
| 2937 |
|
| 2938 |
echo '<div class="btnItem" onclick="netasistanform_open()"> |
| 2939 |
<h6><i class="fas fa-phone-alt squareIcon siziarayalımBg" ></i> Sizi Arayalım</h6> |
| 2940 |
</div>'; |
| 2941 |
} |
| 2942 |
echo ' |
| 2943 |
</div> |
| 2944 |
|
| 2945 |
<div class="netasistan_itemContent-input" id="netasistan-form"> |
| 2946 |
<form method="post"> |
| 2947 |
<h5 class="baslikinput">Sizi Arayalım</h5> |
| 2948 |
<div class="netasistan-input-group"> |
| 2949 |
<input type="text" class="netasistan-form-element" placeholder="Ad" name="netasistan_name" id="netasistan_name" value="<?php echo esc_attr($customerx->first_name); ?>" maxlength="50" required> |
| 2950 |
</div> |
| 2951 |
<div class="netasistan-input-group"> |
| 2952 |
<input type="text" class="netasistan-form-element" placeholder="Soyad" name="netasistan_lastname" id="netasistan_lastname" value="<?php echo esc_attr($customerx->last_name); ?>" maxlength="50" required> |
| 2953 |
</div> |
| 2954 |
<div class="netasistan-input-group"> |
| 2955 |
<input type="number" class="netasistan-form-element" placeholder="Telefon" name="netasistan_number" id="netasistan_number" value="<?php echo esc_attr($phone); ?>" min="0" max="9" maxlength="13" required> |
| 2956 |
</div> |
| 2957 |
<div class="netasistan-input-group"> |
| 2958 |
<input type="email" class="netasistan-form-element" placeholder="E-posta" name="netasistan_email" id="netasistan_email" value="<?php echo esc_attr($customerx->email); ?>" required> |
| 2959 |
</div> |
| 2960 |
<div class="netasistan-input-group"> |
| 2961 |
<input type="text" class="netasistan-form-element" placeholder="Konu" name="netasistan_header" id="netasistan_header" maxlength="70" required> |
| 2962 |
</div> |
| 2963 |
<div class="netasistan-input-group"> |
| 2964 |
<textarea class="netasistan-form-element" placeholder="Açıklama" name="netasistan_content" id="netasistan_content" rows="4" maxlength="500" required></textarea> |
| 2965 |
</div> |
| 2966 |
|
| 2967 |
<div align="right"> |
| 2968 |
<button type="button" class="form-btn btnIptal" id="back_button" name="back_button" onclick="back()">İptal</button> |
| 2969 |
<button type="button" class="form-btn btnGonder" id="send_button" name="send_button" onclick="netasistanform_send()">Gönder</button> |
| 2970 |
</div> |
| 2971 |
|
| 2972 |
</form> |
| 2973 |
<label name="send_response" id="send_response" style="font-size: x-small; color: #545ea5"></label> |
| 2974 |
</div> |
| 2975 |
</div>'; |
| 2976 |
echo '</div>';; ?> |
| 2977 |
<script type="text/javascript"> |
| 2978 |
function netasistanform_open() { |
| 2979 |
var formobj = document.getElementById("netasistan-form"); |
| 2980 |
var buttonsobj = document.getElementById("netasistan-buttons"); |
| 2981 |
if (formobj.style.display === "blok") { |
| 2982 |
formobj.style.display = "none"; |
| 2983 |
buttonsobj.style.display = "block"; |
| 2984 |
|
| 2985 |
} else { |
| 2986 |
formobj.style.display = "block"; |
| 2987 |
buttonsobj.style.display = "none"; |
| 2988 |
} |
| 2989 |
} |
| 2990 |
|
| 2991 |
function back() { |
| 2992 |
var formobj = document.getElementById("netasistan-form"); |
| 2993 |
var buttonsobj = document.getElementById("netasistan-buttons"); |
| 2994 |
document.getElementById('send_response').innerHTML = formobj.style.display; |
| 2995 |
if (formobj.style.display === "block") { |
| 2996 |
formobj.style.display = "none"; |
| 2997 |
buttonsobj.style.display = "block" |
| 2998 |
document.getElementById('send_response').innerHTML = ""; |
| 2999 |
|
| 3000 |
} else { |
| 3001 |
formobj.style.display = "block"; |
| 3002 |
buttonsobj.style.display = "none"; |
| 3003 |
} |
| 3004 |
} |
| 3005 |
|
| 3006 |
document.addEventListener('mouseup', function(e) { |
| 3007 |
var connectionform = document.getElementById('connection-form'); |
| 3008 |
var connectmenu = document.getElementById('netasistan-altlogo'); |
| 3009 |
var connectmenucheck = document.getElementById('connect-menu'); |
| 3010 |
var connectclose = document.getElementById('connect-close'); |
| 3011 |
var formobj = document.getElementById("netasistan-form"); |
| 3012 |
var buttonsobj = document.getElementById("netasistan-buttons"); |
| 3013 |
|
| 3014 |
|
| 3015 |
if (!connectionform.contains(e.target) && !connectmenu.contains(e.target)) { |
| 3016 |
connectionform.style.display = 'none'; |
| 3017 |
connectmenucheck.checked = 'false'; |
| 3018 |
formobj.style.display = 'none' |
| 3019 |
document.getElementById('send_response').innerHTML = ""; |
| 3020 |
buttonsobj.style.display = 'block' |
| 3021 |
|
| 3022 |
} |
| 3023 |
if (connectmenu.contains(e.target)) { |
| 3024 |
if (connectmenucheck.checked == false) { |
| 3025 |
connectionform.style.display = 'none'; |
| 3026 |
formobj.style.display = 'none' |
| 3027 |
buttonsobj.style.display = 'block' |
| 3028 |
document.getElementById('send_response').innerHTML = ""; |
| 3029 |
} else { |
| 3030 |
connectionform.style.display = 'block'; |
| 3031 |
} |
| 3032 |
} |
| 3033 |
if (connectclose.contains(e.target)) { |
| 3034 |
connectionform.style.display = 'none'; |
| 3035 |
connectmenucheck.checked = 'false'; |
| 3036 |
formobj.style.display = 'none' |
| 3037 |
document.getElementById('send_response').innerHTML = ""; |
| 3038 |
buttonsobj.style.display = 'block' |
| 3039 |
} |
| 3040 |
}); |
| 3041 |
|
| 3042 |
function netasistanform_send() { |
| 3043 |
var netasistan_name = document.getElementById('netasistan_name').value; |
| 3044 |
var netasistan_lastname = document.getElementById('netasistan_lastname').value; |
| 3045 |
var netasistan_number = document.getElementById('netasistan_number').value; |
| 3046 |
var netasistan_email = document.getElementById('netasistan_email').value; |
| 3047 |
var netasistan_header = document.getElementById('netasistan_header').value; |
| 3048 |
var netasistan_content = document.getElementById('netasistan_content').value; |
| 3049 |
|
| 3050 |
if (netasistan_name == "" || netasistan_lastname == "" || netasistan_number == "" || netasistan_email == "" || netasistan_header == "" || netasistan_content == "") { |
| 3051 |
document.getElementById('send_response').innerHTML = "Tüm alanlar dolu olmalıdır!"; |
| 3052 |
} else { |
| 3053 |
var data = { |
| 3054 |
'action': 'netgsm_netasistanticket', |
| 3055 |
'netasistan_name': netasistan_name, |
| 3056 |
'netasistan_lastname': netasistan_lastname, |
| 3057 |
'netasistan_number': netasistan_number, |
| 3058 |
'netasistan_email': netasistan_email, |
| 3059 |
'netasistan_header': netasistan_header, |
| 3060 |
'netasistan_content': netasistan_content, |
| 3061 |
}; |
| 3062 |
|
| 3063 |
jQuery.post(ajaxurl, data, function(response) { |
| 3064 |
var obje = JSON.parse(response); |
| 3065 |
if (obje) { |
| 3066 |
if (obje.code == "1000") { |
| 3067 |
document.getElementById('netasistan_name').value = ""; |
| 3068 |
document.getElementById('netasistan_lastname').value = ""; |
| 3069 |
document.getElementById('netasistan_number').value = ""; |
| 3070 |
document.getElementById('netasistan_email').value = ""; |
| 3071 |
document.getElementById('netasistan_header').value = ""; |
| 3072 |
document.getElementById('netasistan_content').value = ""; |
| 3073 |
document.getElementById('send_response').innerHTML = "Kaydınız oluşturuldu."; |
| 3074 |
} else if (obje.code == "1101") { |
| 3075 |
document.getElementById('send_response').innerHTML = "Telefon numaranızı kontrol ediniz. (5XXXXXXXXX)"; |
| 3076 |
} else if (obje.code == "1105") { |
| 3077 |
document.getElementById('send_response').innerHTML = "E-mail adresinizi kontrol ediniz. (test@test.com)"; |
| 3078 |
} else if (obje.code == "0") { |
| 3079 |
document.getElementById('send_response').innerHTML = obje.mesaj; |
| 3080 |
} else { |
| 3081 |
document.getElementById('send_response').innerHTML = obje.mesaj; |
| 3082 |
} |
| 3083 |
} else { |
| 3084 |
document.getElementById('send_response').innerHTML = "Kayıt oluşturulamadı!"; |
| 3085 |
} |
| 3086 |
|
| 3087 |
document.getElementById('send_button').disabled = false; |
| 3088 |
document.getElementById('send_response').disabled = false; |
| 3089 |
|
| 3090 |
}); |
| 3091 |
} |
| 3092 |
} |
| 3093 |
</script> |
| 3094 |
<?php |
| 3095 |
|
| 3096 |
} |
| 3097 |
} |
| 3098 |
|
| 3099 |
function netasistan_phonecontrol($phone) |
| 3100 |
{ |
| 3101 |
if ($phone != "") { |
| 3102 |
if (substr($phone, 0, 1) == "0") { |
| 3103 |
$phone_new = substr($phone, 1, 10); |
| 3104 |
} else if (substr($phone, 0, 2) == "90") { |
| 3105 |
$phone_new = substr($phone, 2, 10); |
| 3106 |
} else if (substr($phone, 0, 3) == "+90") { |
| 3107 |
$phone_new = substr($phone, 3, 10); |
| 3108 |
} else { |
| 3109 |
$phone_new = $phone; |
| 3110 |
} |
| 3111 |
return $phone_new; |
| 3112 |
} |
| 3113 |
} |
| 3114 |
require_once 'wc-netgsm-api.php'; |
| 3115 |
|
| 3116 |
register_activation_hook(__FILE__, 'create_sms_tracking_table'); |
| 3117 |
function create_sms_tracking_table() { |
| 3118 |
global $wpdb; |
| 3119 |
|
| 3120 |
$table_name = $wpdb->prefix . 'sms_notifications'; |
| 3121 |
$charset_collate = $wpdb->get_charset_collate(); |
| 3122 |
|
| 3123 |
$sql = "CREATE TABLE $table_name ( |
| 3124 |
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, |
| 3125 |
product_id BIGINT(20) NOT NULL, |
| 3126 |
customer_id BIGINT(20) DEFAULT NULL, -- nullable customer_id |
| 3127 |
user_name VARCHAR(100) NOT NULL, |
| 3128 |
email VARCHAR(100) NOT NULL, |
| 3129 |
phone VARCHAR(20) NOT NULL, |
| 3130 |
notified TINYINT(1) DEFAULT 0, |
| 3131 |
created_at DATETIME DEFAULT CURRENT_TIMESTAMP, |
| 3132 |
PRIMARY KEY (id) |
| 3133 |
) $charset_collate;"; |
| 3134 |
|
| 3135 |
|
| 3136 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 3137 |
dbDelta($sql); |
| 3138 |
} |
| 3139 |
|
| 3140 |
add_action('woocommerce_review_order_before_submit', function () { |
| 3141 |
?> |
| 3142 |
<div id="cod-otp-area" style="display:none; margin-top:15px;"> |
| 3143 |
<p> |
| 3144 |
<input type="button" class="input-text button" value="OTP Gönder" style="width:100%;" onclick="sendtf2CodeCod()"/> |
| 3145 |
</p> |
| 3146 |
|
| 3147 |
<p> |
| 3148 |
<input type="text" |
| 3149 |
name="cod_otp" |
| 3150 |
id="cod_otp" |
| 3151 |
placeholder="OTP Kodunu Giriniz" |
| 3152 |
class="input-text" |
| 3153 |
style="width:100%;"/> |
| 3154 |
</p> |
| 3155 |
</div> |
| 3156 |
<script> |
| 3157 |
function sendtf2CodeCod() { |
| 3158 |
// Classic checkout (underscore) ve Block checkout (hyphen) alan seçicileri |
| 3159 |
var firstname = jQuery('#billing_first_name, #billing-first_name').first().val() || ''; |
| 3160 |
var lastname = jQuery('#billing_last_name, #billing-last_name').first().val() || ''; |
| 3161 |
var phone = jQuery('#billing_phone, #billing-phone').first().val() || ''; |
| 3162 |
var email = jQuery("input[name*='billing_email'], #billing-email").first().val() || ''; |
| 3163 |
|
| 3164 |
var error = ''; |
| 3165 |
if (firstname == '') { |
| 3166 |
error += '> İsim girilmedi.\n'; |
| 3167 |
} |
| 3168 |
if (lastname == '') { |
| 3169 |
error += '> Soyisim girilmedi.\n'; |
| 3170 |
} |
| 3171 |
if (email == '') { |
| 3172 |
error += '> E-mail adresi girilmedi.\n'; |
| 3173 |
} |
| 3174 |
if (phone == '') { |
| 3175 |
error += '> Telefon numarası girilmedi.\n'; |
| 3176 |
} |
| 3177 |
|
| 3178 |
<?php |
| 3179 |
if (sanitize_text_field(get_option('netgsm_tf2_cash_on_delivery_control')) == '1') { |
| 3180 |
?> |
| 3181 |
if (phone.slice(0, 1) != '0') { |
| 3182 |
error += '> Telefon numarası 0 ile başlamalıdır.\n'; |
| 3183 |
} |
| 3184 |
<?php |
| 3185 |
} |
| 3186 |
?> |
| 3187 |
|
| 3188 |
if (error != '') { |
| 3189 |
alert('Aşağıdaki hatalar alındı : \n\n' + error); |
| 3190 |
return false; |
| 3191 |
} |
| 3192 |
|
| 3193 |
var data = { |
| 3194 |
'action': 'netgsm_sendtf2SMS', |
| 3195 |
'type': 'cod', |
| 3196 |
'phone': phone, |
| 3197 |
'first_name': firstname, |
| 3198 |
'last_name': lastname, |
| 3199 |
'email': email |
| 3200 |
}; |
| 3201 |
|
| 3202 |
jQuery.post(<?php echo json_encode(admin_url('admin-ajax.php')); ?>, data, function (response) { |
| 3203 |
var endChar = response.substring(response.length - 1); |
| 3204 |
if (endChar == '0') { |
| 3205 |
response = response.substring(0, (response.length - 1)); |
| 3206 |
} |
| 3207 |
|
| 3208 |
var obje = JSON.parse(response); |
| 3209 |
if (obje.status == 'success') { |
| 3210 |
alert('Lütfen ' + obje.phone + ' numaralı telefonunuza gelen güvenlik kodunu giriniz.'); |
| 3211 |
jQuery('#tf2Codealert').html('*Lütfen ' + obje.phone + ' numaralı telefonunuza gelen ' + obje.refno + ' referans numaralı güvenlik kodunu giriniz.'); |
| 3212 |
document.getElementById("tf2Code").focus(); |
| 3213 |
jQuery('#sendCode').prop('disabled', true); |
| 3214 |
} else { |
| 3215 |
if (obje.status == 'error' && obje.state == 1) { |
| 3216 |
alert(obje.data + ' Lütfen site yöneticisi ile iletişime geçin.'); |
| 3217 |
} else if (obje.status == 'error' && obje.state == 2) { |
| 3218 |
alert(obje.data); |
| 3219 |
} else if (obje.status == 'error' && obje.state == 4) { |
| 3220 |
alert(obje.data); |
| 3221 |
} else if (obje.status == 'error' && obje.state == 5) { |
| 3222 |
alert(obje.data); |
| 3223 |
} else { |
| 3224 |
alert('Bilinmeyen bir hata oluştu. GSM numarası girdiğinize emin olun. Sorunun devam etmesi halinde lütfen site yöneticisi ile iletişime geçin.'); |
| 3225 |
} |
| 3226 |
} |
| 3227 |
}); |
| 3228 |
} |
| 3229 |
</script> |
| 3230 |
<?php |
| 3231 |
}); |
| 3232 |
add_action('woocommerce_checkout_process', function () { |
| 3233 |
|
| 3234 |
if (isset($_POST['payment_method']) && $_POST['payment_method'] === 'cod') { |
| 3235 |
|
| 3236 |
$netgsm_status = esc_html(get_option("netgsm_status")); |
| 3237 |
$netgsm_otp_cod = esc_html(get_option("netgsm_tf2_cash_on_delivery_control")); |
| 3238 |
if (isset($netgsm_status) && !empty($netgsm_status) && $netgsm_status == 1 && |
| 3239 |
isset($netgsm_otp_cod) && !empty($netgsm_otp_cod) && $netgsm_otp_cod == 1) { |
| 3240 |
|
| 3241 |
$verified_code = get_post_meta(1, $_POST['billing_phone'] . '_2fa', true) ?? ''; |
| 3242 |
$code = $_POST['cod_otp']; |
| 3243 |
if ($code != $verified_code) { |
| 3244 |
wc_add_notice('Doğrulama kodunu yanlış girdiniz!', 'error'); |
| 3245 |
} |
| 3246 |
} |
| 3247 |
} |
| 3248 |
}); |
| 3249 |
|
| 3250 |
// Block Checkout - COD OTP alan kaydı |
| 3251 |
add_action('woocommerce_blocks_loaded', function () { |
| 3252 |
if (!function_exists('woocommerce_register_additional_checkout_field')) return; |
| 3253 |
$netgsm_status = get_option('netgsm_status'); |
| 3254 |
$netgsm_otp_cod = get_option('netgsm_tf2_cash_on_delivery_control'); |
| 3255 |
if ($netgsm_status != 1 || $netgsm_otp_cod != 1) return; |
| 3256 |
woocommerce_register_additional_checkout_field([ |
| 3257 |
'id' => 'netgsm/cod_otp', |
| 3258 |
'label' => 'Kapıda Ödeme OTP Kodu', |
| 3259 |
'location' => 'order', |
| 3260 |
'type' => 'text', |
| 3261 |
'required' => false, |
| 3262 |
]); |
| 3263 |
}); |
| 3264 |
|
| 3265 |
// Block Checkout - COD OTP sunucu taraflı doğrulama |
| 3266 |
add_action('woocommerce_store_api_checkout_update_order_from_request', function ($order, $request) { |
| 3267 |
$netgsm_status = get_option('netgsm_status'); |
| 3268 |
$netgsm_otp_cod = get_option('netgsm_tf2_cash_on_delivery_control'); |
| 3269 |
if ($netgsm_status != 1 || $netgsm_otp_cod != 1) return; |
| 3270 |
if ($order->get_payment_method() !== 'cod') return; |
| 3271 |
|
| 3272 |
$additional_fields = $request->get_param('additional_fields') ?? []; |
| 3273 |
$cod_otp = trim($additional_fields['netgsm/cod_otp'] ?? ''); |
| 3274 |
$billing = $request->get_param('billing_address') ?? []; |
| 3275 |
$billing_phone = trim($billing['phone'] ?? $order->get_billing_phone()); |
| 3276 |
$verified_code = get_post_meta(1, $billing_phone . '_2fa', true) ?? ''; |
| 3277 |
|
| 3278 |
if (empty($cod_otp) || $cod_otp !== $verified_code) { |
| 3279 |
throw new \Automattic\WooCommerce\StoreApi\Exceptions\RouteException( |
| 3280 |
'netgsm_cod_otp_invalid', |
| 3281 |
'Kapıda ödeme doğrulama kodunu yanlış girdiniz!', |
| 3282 |
400 |
| 3283 |
); |
| 3284 |
} |
| 3285 |
}, 8, 2); |
| 3286 |
add_action('woocommerce_admin_order_data_after_billing_address', function ($order) { |
| 3287 |
$iys_checkout_control = esc_html(get_option('netgsm_iys_checkout_control')); |
| 3288 |
if ($iys_checkout_control == 1) { |
| 3289 |
$iys_value = get_post_meta($order->get_id(), '_netgsm_iys_checkout', true); |
| 3290 |
$status_text = ($iys_value == '1') ? 'Evet' : 'Hayır'; |
| 3291 |
$status_color = ($iys_value == '1') ? '#28a745' : '#dc3545'; |
| 3292 |
echo '<p><strong>Netgsm SMS İzni:</strong> <span style="color: ' . $status_color . ';">' . esc_html($status_text) . '</span></p>'; |
| 3293 |
} |
| 3294 |
}); |
| 3295 |
/* |
| 3296 |
global $jal_db_version; |
| 3297 |
$jal_db_version = '4.1'; |
| 3298 |
|
| 3299 |
function jal_install() { |
| 3300 |
global $wpdb; |
| 3301 |
global $jal_db_version; |
| 3302 |
$installed_ver = get_option( "jal_db_version" ); |
| 3303 |
|
| 3304 |
if ( $installed_ver != $jal_db_version ) { |
| 3305 |
|
| 3306 |
$table_name = $wpdb->prefix . 'netgsmsmsreports'; |
| 3307 |
|
| 3308 |
$charset_collate = $wpdb->get_charset_collate(); |
| 3309 |
|
| 3310 |
$sql = "CREATE TABLE $table_name ( |
| 3311 |
id mediumint(9) NOT NULL AUTO_INCREMENT, |
| 3312 |
phone tinytext NOT NULL, |
| 3313 |
trchar int, |
| 3314 |
jobid int, |
| 3315 |
errorcode int, |
| 3316 |
time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, |
| 3317 |
title tinytext NOT NULL, |
| 3318 |
properties tinytext NOT NULL, |
| 3319 |
text text NOT NULL, |
| 3320 |
PRIMARY KEY (id) |
| 3321 |
) $charset_collate;"; |
| 3322 |
|
| 3323 |
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
| 3324 |
dbDelta( $sql ); |
| 3325 |
|
| 3326 |
update_option( "jal_db_version", $jal_db_version ); |
| 3327 |
} |
| 3328 |
} |
| 3329 |
register_activation_hook( __FILE__, 'jal_install' ); |
| 3330 |
|
| 3331 |
function netgsm_setData($phone, $title, $trChar, $text, $properties, $time, $jobid=0, $errorcode=0){ |
| 3332 |
global $wpdb; |
| 3333 |
$table_name = $wpdb->prefix . 'netgsmsmsreports'; |
| 3334 |
|
| 3335 |
$wpdb->insert( |
| 3336 |
$table_name, |
| 3337 |
array( |
| 3338 |
'phone' => $phone, |
| 3339 |
'title' => $title, |
| 3340 |
'text' => $text, |
| 3341 |
'properties' => $properties, |
| 3342 |
'time' => $time, |
| 3343 |
'jobid' => $jobid, |
| 3344 |
'errorcode' => $errorcode, |
| 3345 |
'trchar' => $trChar, |
| 3346 |
) |
| 3347 |
); |
| 3348 |
} |
| 3349 |
|
| 3350 |
|
| 3351 |
|
| 3352 |
|
| 3353 |
function netgsm_update_db_check() { |
| 3354 |
global $jal_db_version; |
| 3355 |
if ( get_site_option( 'jal_db_version' ) != $jal_db_version ) { |
| 3356 |
jal_install(); |
| 3357 |
} |
| 3358 |
} |
| 3359 |
add_action( 'plugins_loaded', 'netgsm_update_db_check' ); |
| 3360 |
*/ |
| 3361 |
|
| 3362 |
|
| 3363 |
|