更改帐单邮寄地址字段类型woocommercce

时间:2016-06-09 16:46:42

标签: php wordpress woocommerce

我想更改帐户页面中某些字段的类型,我想将City从“textfield”更改为<select>(list),我只指定了一些城市,我不希望用户输入任何内容,您是否知道我应该编辑哪些代码? 我试过这个,但我不知道要修改什么!

我希望只选择三个城市(巴黎,伦敦,阿尔及尔)

add_filter( 'woocommerce_billing_fields', 'custom_woocommerce_billing_fields' );

    function custom_woocommerce_billing_fields( $fields ) {

       $fields['billing_city']  = array(
          'label'          => __('City', 'woothemes'),
          'placeholder'    => __('City', 'woothemes'),
          'required'       => true,
          'class'          => array('billing-city')
       );

     return $fields;
    }

先谢谢你了!

1 个答案:

答案 0 :(得分:1)

请试试下面的代码。

add_filter( 'woocommerce_billing_fields', 'custom_woocommerce_billing_fields' );

function custom_woocommerce_billing_fields( $fields ) {

   $fields['billing_city']  = array(
      'type'            => 'select',
      'label'          => __('City', 'woothemes'),
      'placeholder'    => __('City', 'woothemes'),
      'required'       => true,
      'class'          => array('billing-city'),
      'options'     => array(
            'paris' => __('Paris', 'woothemes' ),
            'london' => __('London', 'woothemes' ),
            'algiers' => __('Algiers', 'woothemes' )
        )
   );

 return $fields;
}
相关问题