[英]WooCommerce Shipping State Select
我需要覆盖 WooCommerce 结帐中的所有状态,但我只需要为运输部分执行此操作。
所以“billing_state”在意大利所有当前的州都可以正常工作,我只需要用新州覆盖“shipping_state”。
使用下面的代码将覆盖 billing_states 和运输状态。 如何修改代码以覆盖“shipping_states”
提前致谢
add_filter( 'woocommerce_states', 'custom_woocommerce_states' );
function custom_woocommerce_states( $states ) {
$states['IT'] = array(
//I have to display only these 3 states in shipping Checkout
'TV' => 'Treviso',
'CA' => 'Carità',
'CS' => 'Castrette',
);
return $states;
}
这就是你要找的。 将此添加到您的活动子主题functions.php
请参阅此WebToffee 文章
add_action( 'wp_footer', 'webtoffee_checkout_shipping_filter_it_states' );
function webtoffee_checkout_shipping_filter_it_states() {
if ( ! is_checkout() ) {
return;
}
?>
<script>
jQuery(document).ready(function($) {
$(document.body).on('country_to_state_changed', function() {
var $shipping_country = $('#shipping_country');
var new_shipping_state = '';
switch($shipping_country.val()) {
case 'IT':
new_shipping_state = {'TV': "Treviso", "CA": "Carità", "Cs": "Castrette"};
break;
}
if( ! $.isEmptyObject(new_shipping_state)) {
var optionsAsString = "";
for (var key in new_shipping_state) {
optionsAsString += "<option value='" + key + "'>" + new_shipping_state[key] + "</option>";
}
$( 'select[name="shipping_state"]' ).html( optionsAsString );
}
});
});
</script>
<?php
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.