【问题标题】:Change WooCommerce checkout country field default option displayed label更改 WooCommerce 结帐国家/地区字段默认选项显示标签
【发布时间】:2021-03-23 16:12:13
【问题描述】:

如何编辑现有数组的默认值 - 已设法使用此编辑标签,但无法使用此选项使选项属性工作:

add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
    $fields['billing']['billing_country']['options value="default"'] = 'My new select prompt';
    $fields['billing']['billing_country']['label'] = 'Are you purchasing as a Company Y/N or from the UK?';
    
    return $fields;
}

【问题讨论】:

    标签: php wordpress woocommerce field checkout


    【解决方案1】:

    要更改结帐页面中 WooCommerce 国家/地区字段默认选项显示的值,您可以通过这种方式使用以下复合挂钩:

    add_filter( 'woocommerce_form_field_country', 'filter_form_field_country', 10, 4 );
    function filter_form_field_country( $field, $key, $args, $value ) {
        // Only in checkout page for "billing" city field
        if ( is_checkout() && 'billing_country' === $key ) {
            $search  = esc_html__( 'Select a country / region…', 'woocommerce' ); // String to search
            $replace = esc_html__( 'My new select prompt', 'woocommerce' ); // Replacement string
            $field   = str_replace( $search, $replace, $field );
        }
        return $field;
    }
    

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

    然后你可以继续你的问题代码如下:

    add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
    function custom_override_checkout_fields( $fields ) {
        $fields['billing']['billing_country']['label'] = __('Are you purchasing as a Company Y/N or from the UK?', 'woocommerce');
        
        return $fields;
    }
    

    【讨论】:

    • 哇,非常感谢 LoicTheAztec 的帮助 :):):) 使用旧的国家/地区下拉字段根据要求触发税收选项:如果来自英国 - 增值税 20% 来自在英国以外为公司购买 - 销售税为零 如果来自英国以外并作为个人购买 - 销售税 20% 效果很好,现在找不到可以做到这一点的插件
    • 会做 - 这里是新的,所以不确定如何
    猜你喜欢
    • 2016-01-01
    • 2021-10-27
    • 2018-09-28
    • 2019-08-13
    • 1970-01-01
    • 2015-04-09
    • 2017-05-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多