我正在尝试找到一种方法从 WooCommerce 结帐页面的“州”下拉列表中删除一些美国州。
状态列表:
- 夏威夷
- 阿拉斯加州
- 武装部队 (AA)
- 武装部队 (AE)
- 武装部队 (AP)
到目前为止我做了什么:
我一直在手动删除它们,如本 link 中所述.但这不是一个好方法,因为每次更新 WooCommerce 时更改都会被覆盖。
我找到的替代方案: 在这个链接上WooCommerce restrict shipping to states based on category ,如果满足特定条件,则有一种方法可以设置运输状态。 我想知道是否可以取消设置 五个状态。这对我来说听起来比设置 50 个状态更合乎逻辑。但不幸的是,我找不到任何有用的东西。
有什么想法可以成为可能的解决方案吗?
最佳答案
最简单的方法是使用专用过滤器 Hook woocommerce_states
以这种方式删除它们:
add_filter( 'woocommerce_states', 'custom_us_states', 10, 1 );
function custom_us_states( $states ) {
$non_allowed_us_states = array( 'AK', 'HI', 'AA', 'AE', 'AP');
// Loop through your non allowed us states and remove them
foreach( $non_allowed_us_states as $state_code ) {
if( isset($states['US'][$state_code]) )
unset( $states['US'][$state_code] );
}
return $states;
}
代码进入事件子主题(或事件主题)的 functions.php 文件。测试和工作。
Then you can add some condition or make a custom settings page like in the threads below:
关于php - 在 Woocommerce Checkout 上删除一个国家的特定州,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53678249/