【问题标题】:Blank all WooCommerce shipping checkout fields空白所有 WooCommerce 运输结帐字段
【发布时间】:2020-12-31 16:36:04
【问题描述】:

我遇到了这个How to blank all WooCommerce checkout fields by default except country? 类似的问题,它有一个满足我需要的答案代码,但是当客户单击结帐按钮时,此代码将清除所有 woocommerce 运输和结算结帐字段。

如果我只希望运输字段为空,代码将如何显示?

【问题讨论】:

  • 像魅力一样工作。感谢先生您的宝贵时间!

标签: php wordpress woocommerce field checkout


【解决方案1】:

要空白所有 WooCommerce 运输结帐字段,您将使用以下内容:

add_filter('woocommerce_checkout_get_value', 'checkout_get_value_filter', 10, 2 );
function checkout_get_value_filter( $value, $input ) {
    if ( strpos($input, "shipping_") === 0 ) {
        return '';
    }
    return $value;
}

或者也这样指定每个相关的运输字段键:

add_filter('woocommerce_checkout_get_value', 'checkout_get_value_filter', 10, 2 );
function checkout_get_value_filter( $value, $input ) {
    $key_fields = array(
        'shipping_first_name',
        'shipping_last_name',
        'shipping_company',
        'shipping_country',
        'shipping_address_1',
        'shipping_address_2',
        'shipping_city',
        'shipping_country',
        'shipping_state',
        'shipping_postcode',
    );
    
    if ( in_array($input, $key_fields) ) {
        return '';
    }
    return $value;
}

代码在您的活动子主题(或活动主题)的functions.php 文件中。它应该可以工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-13
    • 2015-04-20
    • 2019-04-01
    • 1970-01-01
    • 2019-10-15
    • 1970-01-01
    • 2019-01-20
    • 2018-03-01
    相关资源
    最近更新 更多