簡體   English   中英

wc_add_notice 的問題

[英]Problems with wc_add_notice

在我的結帳表單中,我在 function.php 中添加了 google-captcha。 然后我正在驗證驗證碼不是空的也不是假的:

function my_custom_checkout_field_process($data, $errors) {
    // Check if set, if its not set add an error.
    if(count($errors->get_error_messages()) == 0) {
        if ( empty( $_REQUEST['g-recaptcha-response'] ) || !(google_recaptcha( $_REQUEST['g-recaptcha-response'] )) ) {
            wc_add_notice( __( 'Please enter correct captcha.', 'error' ));

        }
    }
}

但是函數 wc_add_notice 僅在下一頁(thankyou.php)中顯示錯誤消息。 訂單正在發送。 但我希望如果驗證碼為假或空,thankyou.php 不會加載。 我應該在此代碼中添加什么? 它必須像具有必填字段的情況一樣起作用。 如果出現故障 - 會出現錯誤消息並且用戶停留在同一頁面上。

我相信您應該刪除if(count($errors->get_error_messages()) == 0)並且它應該可以工作。 由於該if語句,您在感謝頁面上收到錯誤消息。

function my_custom_checkout_field_process($data, $errors) {

        if ( empty( $_REQUEST['g-recaptcha-response'] ) || !(google_recaptcha( $_REQUEST['g-recaptcha-response'] )) ) {
            throw new Exception( __( 'Please enter correct captcha.', 'error' ));

        }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM