![](/img/trans.png)
[英]Styling the payment methods in the WooCommerce checkout page (Custom Javascript required)
[英]WooCommerce custom checkout verification not working
我目前正在嘗試進行第二次(第一次)結帳驗證。 為此,我需要阻止標准的WooCommerce結帳驗證。 之前,我已經使用很多表格進行過此操作,但是這次觸發器沒有響應。
我的期望:
當用戶單擊“下訂單”按鈕時,不應運行標准的WooCommerce結帳驗證,並且瀏覽器會警告我的文本。
怎么了:
單擊按鈕時,看不到任何文本/警報。
我的代碼:
jQuery(document).ready(function () {
var checkoutForm = document.querySelector('.woocommerce-checkout');
var postcode = jQuery('#billing_postcode', checkoutForm);
if (checkoutForm != null) {
checkoutFormValidation(checkoutForm, postcode);
}
});
function checkoutFormValidation(checkoutForm, postcode) {
var checkoutButton = checkoutForm.querySelector('button[type="submit"]');
checkoutButton.addEventListener('click', function (e) {
e.preventDefault();
alert("Clicked!");
});
}
我已經檢查了所有內容,並且該文件包含在結帳中。 所以不知道為什么這行不通。
我找到了解決方案。 問題是,默認情況下會觸發另一個驗證功能。 因此,如果您只想添加自定義驗證而不丟失WooCommerce驗證,則無法按照我嘗試的方式進行。 因此解決方案是使用WooCommerce驗證功能:
jQuery(document.body).on("checkout_error", function () {
alert("Clicked!");
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.