亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 WooCommerce 中結帳時預定義的運輸郵政編碼驗證

在 WooCommerce 中結帳時預定義的運輸郵政編碼驗證

PHP
LEATH 2023-06-18 17:23:14
我希望達到的目標我試圖在結帳時添加一個控件,確保在選擇“運送到另一個地址”時提供正確的郵政編碼。我的代碼的問題我正在使用的代碼沒有任何反應。沒有消息,什么都沒有。無論如何都可以下訂單。我的問題我的代碼有什么問題或錯誤在哪里?到目前為止我的代碼add_action( 'woocommerce_after_checkout_validation' , 'deny_outside_zone_message', 10, 2,);function deny_outside_zone_message( $fields, $errors ) {    // the accepted delivery zones    $del_zones_array = array('30030', '30032', '30033');    // check if the postal code (billing or shipping) if within the array    if (! in_array('shipping_postcode', $del_zones_array ) ) {    // if the postal is not within the array, deny checkout    echo "The ZIP you provided is not available for oneline deliveries.";    return;    }}
查看完整描述

1 回答

?
哈士奇WWW

TA貢獻1799條經驗 獲得超6個贊

shipping_postcode未在您的代碼中設置


// Validate

function action_woocommerce_after_checkout_validation( $data, $error ) {        

    // The accepted delivery zones

    $del_zones_array = array( 30030, 30032, 30033 );


    // If the postal is not within the array, deny checkout

    if( ! in_array( $data['shipping_postcode'], $del_zones_array ) ) {

        $error->add( 'validation', 'The ZIP you provided is not available for oneline deliveries.' );

    }

}

add_action('woocommerce_after_checkout_validation', 'action_woocommerce_after_checkout_validation', 10, 2 );



查看完整回答
反對 回復 2023-06-18
  • 1 回答
  • 0 關注
  • 147 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號