我正在为Woocommerce商店的订单确定基于邮政编码的最低订购量。 另外,一旦用户输入邮政编码(例如,他需要多少结帐),我就会显示基于邮政编码的自定义错误消息。 因此,为了防止用户键入无效的邮政编码(这意味着我们不提供的邮政编码),我在下拉菜单中显示下拉列表以选择其有效的邮政编码。
基于此线程Change postcode shipping field to a dropdown in Woocommerce,我可以使用选项将邮政编码字段下拉至下拉列表。
但是当我从下拉列表中选择任何选项时,我收到Woocommerce的“邮政编码无效”错误。另外,我的自定义消息也不会显示。
下面是我在上述线程中使用的代码。
add_filter( 'woocommerce_default_address_fields','customize_postcode_fields' );
function customize_postcode_fields( $adresses_fields ) {
$adresses_fields['postcode']['type'] = 'select';
$adresses_fields['postcode']['options'] = array(
'' => __('Select your postcode','woocommerce'),'option_1' => '000001','option_2' => '000002','option_3' => '000003'
);
return $adresses_fields;
}