WooCommerce - 格式化的帐单邮寄地址

时间:2014-08-16 09:15:45

标签: php wordpress

我有点沮丧了几天,试图找到解决方案,所以任何帮助都会非常感激。

在Wordpress的myfunctions.php中,我添加了以下内容:

add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );

// Our hooked in function - $address_fields is passed via the filter!
function custom_override_default_address_fields( $address_fields ) {
     unset($address_fields['postcode']);
     $address_fields['company']['required'] = false;

     $address_fields['chamber_of_commerce_no'] = array(
        'label'     => __('Chamber of Commerce No', 'woocommerce'),
    'placeholder'   => _x('Chamber of Commerce No', 'placeholder', 'woocommerce'),
    'required'  => true,
    'class'     => array('form-row-wide'),
    'clear'     => true
     );

     $address_fields['fiscal_code'] = array(
        'label'     => __('Fiscal Code', 'woocommerce'),
    'placeholder'   => _x('For romanian companies', 'placeholder', 'woocommerce'),
    'required'  => false,
    'class'     => array('form-row-wide'),
    'clear'     => true
     );

    $address_fields['vat_code'] = array(
        'label'     => __('VAT Code', 'woocommerce'),
    'placeholder'   => _x('For foreign companies', 'placeholder', 'woocommerce'),
    'required'  => false,
    'class'     => array('form-row-wide'),
    'clear'     => true
     );

     $address_fields['bank_account_no'] = array(
        'label'     => __('Bank Account No', 'woocommerce'),
    'placeholder'   => _x('Bank Account No', 'placeholder', 'woocommerce'),
    'required'  => true,
    'class'     => array('form-row-wide'),
    'clear'     => true
     );

     $address_fields['bank'] = array(
        'label'     => __('Bank', 'woocommerce'),
    'placeholder'   => _x('Bank', 'placeholder', 'woocommerce'),
    'required'  => true,
    'class'     => array('form-row-wide'),
    'clear'     => true
     );


     return $address_fields;
    }

在此之后,我尝试将字段添加到get_formatted_billing_address函数:

 public function get_formatted_billing_address() {
        if ( ! $this->formatted_billing_address ) {

            // Formatted Addresses
            $address = apply_filters( 'woocommerce_order_formatted_billing_address', array(
                'company'       => $this->billing_company,
                'address_1'         => $this->billing_address_1,
                'address_2'         => $this->billing_address_2,
                'city'          => $this->billing_city,
                'country'       => $this->billing_country,
                'bank_account_no'   => $this->billing_bank_account_no,
                'bank'          => $this->billing_bank,
                'chamber_of_commerce_no'=> $this->billing_chamber_of_commerce_no,
                'fiscal_code'       => $this->billing_fiscal_code,
                'vat_code'      => $this->billing_vat_code

            ), $this );

            $this->formatted_billing_address = WC()->countries->get_formatted_address( $address );
        }
        return $this->formatted_billing_address;
    }

它不起作用。 然后我尝试添加过滤器:

    add_filter ('woocommerce_order_formatted_billing_address', 'custom_override_formatted_billing_address');



function custom_override_formatted_billing_address () {

        $address = array(

        'company'       => $this->billing_company,

        'address_1'         => $this->billing_address_1,

        'address_2'         => $this->billing_address_2,

        'city'          => $this->billing_city,

        'state'         => $this->billing_state,

        'country'       => $this->billing_country,

        'bank_account_no'   => $this->billing_bank_account_no,

        'bank'          => $this->billing_bank,

        'chamber_of_commerce_no'=> $this->billing_chamber_of_commerce_no,

        'fiscal_code'       => $this->billing_fiscal_code,

        'vat_code'      => $this->billing_vat_code

);



    return $address;

   }

但是,它没有用。

我该怎么做才能做到这一点?

谢谢!

1 个答案:

答案 0 :(得分:0)

你需要这样做:

add_filter('woocommerce_localisation_address_formats', 'your_func')