我希望達到的目標我試圖在結帳時添加一個控件,確保在選擇“運送到另一個地址”時提供正確的郵政編碼。我的代碼的問題我正在使用的代碼沒有任何反應。沒有消息,什么都沒有。無論如何都可以下訂單。我的問題我的代碼有什么問題或錯誤在哪里?到目前為止我的代碼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 );
- 1 回答
- 0 關注
- 147 瀏覽
添加回答
舉報
0/150
提交
取消