آره، الان مشخص شد مشکل کجاست. 👍
از اسکرینشاتی که فرستادی، دکمه WoodMart در لیست محصولات این کلاسها را دارد:
```text
wd-add-btn wd-add-btn-replace
```
و خود لینک افزودن به سبد خرید هم این کلاس را دارد:
```text
add_to_cart_button ajax_add_to_cart add-to-cart-loop
```
بنابراین کدی که قبلاً دادم فقط `.single_add_to_cart_button` را میگرفت و **این دکمه WoodMart را نمیگرفت**.
### این کد را کامل جایگزین کد قبلی کن
در:
**Elementor → Custom Code → کد قبلی → Edit**
کل کد قبلی را پاک کن و این را بگذار:
```javascript
jQuery(function ($) {
const POPUP_ID = 19893;
let pendingButton = null;
let rulesAccepted = false;
/*
|--------------------------------------------------------------------------
| دکمههای Add To Cart
|--------------------------------------------------------------------------
| WoodMart Shop:
| .wd-add-btn .add_to_cart_button
|
| Single Product:
| .single_add_to_cart_button
|--------------------------------------------------------------------------
*/
$(document).on(
'click',
'.wd-add-btn .add_to_cart_button, .single_add_to_cart_button',
function (e) {
const button = $(this);
/*
| اگر قوانین قبلاً تأیید شده
| اجازه بده WooCommerce ادامه دهد
*/
if (button.data('rules-accepted') === true) {
button.removeData('rules-accepted');
return true;
}
/*
| جلوگیری از Add To Cart
*/
e.preventDefault();
e.stopImmediatePropagation();
/*
| ذخیره دکمه
*/
pendingButton = button;
/*
| Reset
*/
$('#rules-accept')
.prop('checked', false);
$('#rules-error')
.hide();
$('.confirm-rules-btn')
.addClass('rules-disabled');
/*
| باز کردن Popup
*/
if (
typeof elementorProFrontend !== 'undefined' &&
elementorProFrontend.modules &&
elementorProFrontend.modules.popup
) {
elementorProFrontend.modules.popup.showPopup({
id: POPUP_ID
});
} else {
console.error(
'Elementor Popup module is not available.'
);
}
return false;
}
);
/*
|--------------------------------------------------------------------------
| Checkbox قوانین
|--------------------------------------------------------------------------
*/
$(document).on(
'change',
'#rules-accept',
function () {
if ($(this).is(':checked')) {
$('.confirm-rules-btn')
.removeClass('rules-disabled');
$('#rules-error')
.hide();
} else {
$('.confirm-rules-btn')
.addClass('rules-disabled');
}
}
);
/*
|--------------------------------------------------------------------------
| تأیید قوانین و افزودن محصول
|--------------------------------------------------------------------------
*/
$(document).on(
'click',
'.confirm-rules-btn',
function (e) {
e.preventDefault();
e.stopPropagation();
/*
| بررسی تیک قوانین
*/
if (!$('#rules-accept').is(':checked')) {
$('#rules-error')
.fadeIn();
return false;
}
/*
| بررسی وجود دکمه
*/
if (!pendingButton) {
console.error(
'Add to Cart button not found.'
);
return false;
}
/*
| ذخیره دکمه
*/
const button = pendingButton;
/*
| اجازه یک بار Add To Cart
*/
button.data(
'rules-accepted',
true
);
/*
| بستن Popup
*/
if (
typeof elementorProFrontend !== 'undefined' &&
elementorProFrontend.modules &&
elementorProFrontend.modules.popup
) {
elementorProFrontend.modules.popup.closePopup({
id: POPUP_ID
});
}
/*
| اجرای دوباره دکمه
*/
setTimeout(function () {
button.trigger('click');
pendingButton = null;
}, 300);
return false;
}
);
});
```
### الان Selector اصلی سایت تو
طبق چیزی که از Inspect فرستادی، این قسمت برای WoodMart درست است:
```css
.wd-add-btn .add_to_cart_button
```
و برای صفحه جزئیات محصول هم این را پوشش دادهایم:
```css
.single_add_to_cart_button
```
یعنی کد بالا هر دو حالت را پوشش میدهد:
**صفحه فروشگاه:**
`افزودن به سبد خرید` → Popup
**صفحه جزئیات محصول:**
`افزودن به سبد خرید` → Popup
---
### یک نکته مهم درباره Popup
داخل Popup حتماً این کلاس را روی دکمه تأیید داشته باش:
**Advanced → CSS Classes**
```text
confirm-rules-btn
```
و HTML چکباکس:
```html
لطفاً ابتدا قوانین و شرایط خرید را بپذیرید.
```
و **Popup ID = `19893`** است که در کد هم وارد شده.
---
### حالا یک تست انجام بده
بعد از ذخیره کد:
1. کش Elementor را پاک کن.
2. کش WoodMart/کش سایت را پاک کن.
3. `Ctrl + F5` بزن.
4. روی **افزودن به سبد خرید** همان دکمهای که در تصویر فرستادی کلیک کن.
باید **Popup 19893** باز شود.
اگر این بار Popup باز شد ولی بعد از زدن «تأیید و افزودن به سبد خرید» محصول اضافه نشد، مرحله بعدی را برای **AJAX خود WoodMart** تنظیم میکنیم؛ مخصوصاً چون در تصویر مشخص است WoodMart از `ajax_add_to_cart` استفاده میکند.