php - 在 Woocommerce 中将结帐国家/地区下拉菜单设置为只读

标签 php woocommerce checkout readonly country

我希望 woocommerce 上的国家/地区下拉菜单为只读。 Country Image

我已经将默认国家/地区设置为澳大利亚,但我希望它们是只读的。

最佳答案

Kashalo 的答案是正确的......您还可以使用其他多种方法之一:

1) 仅适用于 Checkout 帐单国家/地区:

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) 仅适用于结帐和我的帐户帐单国家/地区:

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 对于 Checkout 帐单和送货国家/地区:

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) 对于“结帐”和“我的帐户”帐单及送货国家/地区:

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;
}

关于php - 在 Woocommerce 中将结帐国家/地区下拉菜单设置为只读,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52279966/

相关文章:

java - Android-无法使用 woocommerce api 创建订单

php - 新闻 | Woocommerce 自定义注册表格

php - 在 Woocommerce 编辑订单页面中显示可编辑的自定义字段值

php - 为引用 ID 生成随机但唯一的数字

php - 尝试使用 System_Daemon 设置 PHP 守护程序,但在运行时遇到问题

php - 自动检查 Woocommerce 结帐页面中的创建帐户字段

php - 在 Woocommerce 结帐中为产品类别中的特定虚拟产品启用送货地址

php - 结帐字段 - 使 billing_address_2 高于 billing_address_1

php mysql查询仅获取列中的第一个值

php - 电子邮件表格不起作用