首页 文章

编辑WooCommerce结帐页面帐单地址字段

提问于
浏览
1

我想编辑WooCommerce结帐页面的帐单邮寄地址 . 我想编辑我的结帐页面的结算状态 . 我尝试在我的孩子主题中首先进行编辑 .

然后我尝试编辑class-wc-checkout.php文件:

// Billing address
$billing_address = array();
    if ( $this->checkout_fields['billing'] ) {
        foreach ( array_keys( $this->checkout_fields['billing'] ) as $field ) {
            $field_name = str_replace( 'billing_', '', $field );
            $billing_address[ $field_name ] = $this->get_posted_address_data( $field_name );
        }
    }

没有成功 . 我怎样才能做到这一点?

谢谢 .

1 回答

  • 1

    重要建议:切勿触摸WooCommerce插件核心文件,避免:重要错误丢失更新插件时所做的更改


    要自定义WooCommerce,您可以:通过主题覆盖模板(将模板复制到您的活动主题) . 使用操作和过滤器挂钩(在活动主题的function.php文件中) .


    edit / create / remove / reorder checkout fields 我们可以使用这2个过滤钩子:

    • 'woocommerce_checkout_fields'

    或者在特定情况下你需要使用

    • 'woocommerce_default_address_fields' (适用于以下所有结算和发货默认字段)

    此处是结算和发货默认字段列表:

    country
    first_name
    last_name
    company
    address_1
    address_2
    city
    state
    postcode
    

    例如,要使 'billing_state' 字段成为必需:

    add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
    function custom_override_default_address_fields( $address_fields ) {
    
        // we are changing here billing_state field to required
        $address_fields['billing']['billing_state']['required'] = true;
    
        return $address_fields;
    }
    

    每个字段都包含一个可以编辑的属性数组:

    type – type of field (text, textarea, password, select)
    label – label for the input field
    placeholder – placeholder for the input
    class – class for the input
    required – true or false, whether or not the field is require
    clear – true or false, applies a clear fix to the field/label
    label_class – class for the label element
    options – for select boxes, array of options (key => value pairs)
    

    结帐字段分为4组:

    • 运输领域

    • 结算字段

    • 帐户字段

    • 订单字段(备注,评论)


    参考文献:

相关问题