1 回答
TA贡献2019条经验 获得超9个赞
显示错误信息需要满足的条件:(在代码中作为注释添加的解释)
必须选择当地取货。
邮政编码不得存在于预定邮政编码数组中
function zip_code_validator_for_local_home_delivery( $data, $error ) {
/* Settings */
// Zones
$del_zones_array = array( 30030, 30032, 30033 );
// Shipping method
$shipping_method = 'local_pickup:4';
/* End settings */
// Get chosen shipping method ID
$chosen_shipping_method_id = WC()->session->get( 'chosen_shipping_methods' )[0];
// If local pickup is the chosen shipping method && ZIP code NOT in array
if ( $chosen_shipping_method_id == $shipping_method && !in_array( $data['shipping_postcode'], $del_zones_array ) ) {
$error->add( 'validation', 'We\'re sorry, but this address is outside of our online order delivery area.<br>Please contact us for assistance or choose the local pickup option.' );
}
}
add_action('woocommerce_after_checkout_validation', 'zip_code_validator_for_local_home_delivery', 10, 2 );
- 1 回答
- 0 关注
- 115 浏览
添加回答
举报