| 1 |
function openModal() { |
| 2 |
document.getElementById("Basalam-connect-modal").style.display = "block"; |
| 3 |
} |
| 4 |
|
| 5 |
function closeModal() { |
| 6 |
document.getElementById("Basalam-connect-modal").style.display = "none"; |
| 7 |
} |
| 8 |
|
| 9 |
jQuery(document).ready(function ($) { |
| 10 |
$("#basalam-search-btn").on("click", function (event) { |
| 11 |
event.preventDefault(); |
| 12 |
var searchTerm = $("#basalam-product-search").val(); |
| 13 |
var wooProductId = $("#Basalam-woo-product-id").val(); |
| 14 |
|
| 15 |
if (searchTerm.length > 0) { |
| 16 |
$("#basalam-product-results").html("<p>در حال جستجو...</p>"); |
| 17 |
$.ajax({ |
| 18 |
url: ajaxurl, |
| 19 |
type: "POST", |
| 20 |
data: { |
| 21 |
action: "basalam_search_products", |
| 22 |
title: searchTerm, |
| 23 |
woo_product_id: wooProductId, |
| 24 |
}, |
| 25 |
success: function (response) { |
| 26 |
$("#basalam-product-results").html(response); |
| 27 |
}, |
| 28 |
error: function () { |
| 29 |
$("#basalam-product-results").html(error); |
| 30 |
}, |
| 31 |
}); |
| 32 |
} else { |
| 33 |
alert("لطفاً عنوان � |
| 34 |
حصول را وارد کنید."); |
| 35 |
} |
| 36 |
}); |
| 37 |
|
| 38 |
$(document).on("click", ".basalam-connect-btn", function () { |
| 39 |
const $btn = $(this); |
| 40 |
const BasalamProductId = $btn.data("basalam-product-id"); |
| 41 |
const wooProductId = $btn.data("woo-product-id"); |
| 42 |
var nonce = $btn.data("_wpnonce"); |
| 43 |
if (!BasalamProductId || !wooProductId) { |
| 44 |
alert("� |
| 45 |
شخصات � |
| 46 |
حصول ناقص است."); |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
$btn.text("اتصال...").prop("disabled", true); |
| 51 |
|
| 52 |
$.ajax({ |
| 53 |
url: ajaxurl, |
| 54 |
method: "POST", |
| 55 |
data: { |
| 56 |
action: "basalam_connect_product", |
| 57 |
woo_product_id: wooProductId, |
| 58 |
basalam_product_id: BasalamProductId, |
| 59 |
_wpnonce: nonce, |
| 60 |
}, |
| 61 |
success: function (data) { |
| 62 |
if (data.success) { |
| 63 |
alert(data.data?.message || "ع� |
| 64 |
لیات با � |
| 65 |
وفقیت انجا� |
| 66 |
شد."); |
| 67 |
location.reload(); |
| 68 |
} else { |
| 69 |
alert(data.data?.message || "خطایی رخ داده است."); |
| 70 |
} |
| 71 |
}, |
| 72 |
error: function (xhr) { |
| 73 |
let response; |
| 74 |
try { |
| 75 |
response = JSON.parse(xhr.responseText); |
| 76 |
} catch (e) { |
| 77 |
response = {}; |
| 78 |
} |
| 79 |
alert(response?.data?.message || "خطایی رخ داده است."); |
| 80 |
}, |
| 81 |
}); |
| 82 |
}); |
| 83 |
}); |
| 84 |
|