在Woocommerce中将结帐国家/地区下拉列表设为只读 [英] Make checkout country dropdown readonly in Woocommerce
本文介绍了在Woocommerce中将结帐国家/地区下拉列表设为只读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望woocommerce的国家/地区下拉列表为只读.
I want country dropdown on woocommerce as readonly.
我已经将默认国家/地区设置为澳大利亚,但我希望它们是只读的.
I already set the default country to australia but I want them to be readonly.
推荐答案
Kashalo的答案是正确的……您还可以使用以下多种其他方式之一:
The answer of Kashalo is correct… You can also use one of this multiple other ways:
1)仅适用于结帐结算国家/地区:
1) For Checkout Billing country only:
add_filter('woocommerce_checkout_fields', 'readdonly_billing_country_select_field');
function readdonly_billing_country_select_field( $fields ) {
// Set billing and shipping country to AU
WC()->customer->set_billing_country('AU');
// Make billing country field read only
$fields['billing']['billing_country']['custom_attributes'] = array( 'disabled' => 'disabled' );
return $fields;
}
2)仅适用于结帐"和我的帐户帐单国家/地区":
2) For Checkout and My account Billing country only:
add_filter('woocommerce_billing_fields', 'readdonly_billing_country_select_field');
function readdonly_billing_country_select_field( $fields ) {
// Set billing and shipping country to AU
WC()->customer->set_billing_country('AU');
// Make billing country field read only
$fields['billing_country']['custom_attributes'] = array( 'disabled' => 'disabled' );
return $fields;
}
3对于结帐帐单和运送国家/地区:
3 For Checkout billing and shipping country:
add_filter('woocommerce_checkout_fields', 'readdonly_country_select_field');
function readdonly_country_select_field( $fields ) {
// Set billing and shipping country to AU
WC()->customer->set_billing_country('AU');
WC()->customer->set_shipping_country('AU');
// Make billing and shipping country field read only
$fields['billing']['billing_country']['custom_attributes'] = array( 'disabled' => 'disabled' );
$fields['shipping']['shipping_country']['custom_attributes'] = array( 'disabled' => 'disabled' );
return $fields;
}
4)对于结帐"和我的帐户帐单和运送国家/地区":
4) For Checkout and My account billing and shipping country:
add_filter('woocommerce_default_address_fields', 'readdonly_country_select_field');
function readdonly_country_select_field( $fields ) {
// Set billing and shipping country to AU
WC()->customer->set_billing_country('AU');
WC()->customer->set_shipping_country('AU');
// Make country field read only
$fields['country']['custom_attributes'] = array( 'disabled' => 'disabled' );
return $fields;
}
这篇关于在Woocommerce中将结帐国家/地区下拉列表设为只读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文