【问题标题】:How to blank all WooCommerce checkout fields by default except country?默认情况下,除国家/地区外,如何空白所有 WooCommerce 结帐字段?
【发布时间】:2019-08-13 22:18:13
【问题描述】:

在我的 WooCommerce 结帐页面上,我希望帐单字段为空白,但帐单国家/地区除外。

我用它来确保结帐表格在填写时是空白的:

add_filter('woocommerce_checkout_get_value','__return_empty_string',10);

但是,我确实希望填写帐单国家/地区字段,并默认为美国。所以我得到了这个:

add_filter( 'default_checkout_billing_country', 'change_default_checkout_country' );

function change_default_checkout_country() {
  return 'US'; 
}

但只要我有第一个过滤器,该字段就会显示为空白。我怎样才能将除帐单国家/地区以外的所有字段都留空?

【问题讨论】:

    标签: php wordpress woocommerce checkout country


    【解决方案1】:

    请尝试以下操作,这将清空所有结帐字段,但将为特定国家/地区设置的帐单和送货国家/地区除外:

    add_filter('woocommerce_checkout_get_value', 'checkout_get_value_filter', 10, 2 );
    function checkout_get_value_filter( $value, $input ) {
        // The defined country code
        $country_code = 'US';
    
        // Set the billing and shipping country
        WC()->customer->set_billing_country($country_code);
        WC()->customer->set_shipping_country($country_code);
    
        // Display only the billing and shipping country
        if( 'billing_country' === $input || 'shipping_country' === $input ){
            return $country_code;
        } else {
            return '';
        }
    }
    

    代码在您的活动子主题(或活动主题)的 function.php 文件中。经过测试并且可以工作。

    【讨论】:

      猜你喜欢
      • 2016-01-01
      • 2021-03-23
      • 2021-10-27
      • 1970-01-01
      • 1970-01-01
      • 2015-04-09
      • 2020-12-31
      • 2021-03-24
      • 2016-09-03
      相关资源
      最近更新 更多