更改此代码以包含多个邮政编码
Change this code to include multiple postcodes
目前,如果邮政编码以“BT”开头,则使用以下代码向 WooCommerce 添加附加费,但我还想添加更多,如果我将其更改为“BT”、“IM”,我会收到错误
function woocommerce_bt_postcode_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
if ( $woocommerce->customer->get_shipping_country() === 'GB' ) {
$postcode = $woocommerce->customer->get_shipping_postcode();
if ( isset( $postcode )
&& strtoupper( substr( trim( $postcode ), 0, 2 ) ) === 'BT' ) {
$woocommerce->cart->add_fee( 'NI Surcharge', 57, true, '' );
}
}
}
add_action( 'woocommerce_cart_calculate_fees', 'woocommerce_bt_postcode_surcharge' );
function woocommerce_bt_postcode_surcharge() {
global $woocommerce;
if (is_admin() && !defined('DOING_AJAX'))
return;
$allowed_postcodes = array('IM', 'BT');
if ($woocommerce->customer->get_shipping_country() === 'GB') {
$postcode = $woocommerce->customer->get_shipping_postcode();
if (isset($postcode) && in_array(strtoupper(substr(trim($postcode), 0, 2)), $allowed_postcodes)) {
$woocommerce->cart->add_fee('NI Surcharge', 57, true, '');
}
}
}
add_action('woocommerce_cart_calculate_fees', 'woocommerce_bt_postcode_surcharge');
目前,如果邮政编码以“BT”开头,则使用以下代码向 WooCommerce 添加附加费,但我还想添加更多,如果我将其更改为“BT”、“IM”,我会收到错误
function woocommerce_bt_postcode_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
if ( $woocommerce->customer->get_shipping_country() === 'GB' ) {
$postcode = $woocommerce->customer->get_shipping_postcode();
if ( isset( $postcode )
&& strtoupper( substr( trim( $postcode ), 0, 2 ) ) === 'BT' ) {
$woocommerce->cart->add_fee( 'NI Surcharge', 57, true, '' );
}
}
}
add_action( 'woocommerce_cart_calculate_fees', 'woocommerce_bt_postcode_surcharge' );
function woocommerce_bt_postcode_surcharge() {
global $woocommerce;
if (is_admin() && !defined('DOING_AJAX'))
return;
$allowed_postcodes = array('IM', 'BT');
if ($woocommerce->customer->get_shipping_country() === 'GB') {
$postcode = $woocommerce->customer->get_shipping_postcode();
if (isset($postcode) && in_array(strtoupper(substr(trim($postcode), 0, 2)), $allowed_postcodes)) {
$woocommerce->cart->add_fee('NI Surcharge', 57, true, '');
}
}
}
add_action('woocommerce_cart_calculate_fees', 'woocommerce_bt_postcode_surcharge');