【问题标题】:woocommerce address_2 dropdown placeholder not showingwoocommerce address_2 下拉占位符未显示
【发布时间】:2020-12-17 21:33:11
【问题描述】:

我已将 address_2 创建为下拉菜单,但占位符未显示。

/* address_2 dropdown */


add_filter( 'woocommerce_default_address_fields' , 'address2_dropdown' );

function address2_dropdown( $address_fields ) {

    // address_2
    $address_fields['address_2']['type'] = 'select';
    $address_fields['address_2']['placeholder'] = 'Adresse';
    $address_fields['address_2']['options'] = array(
        '' => '',
        'villa' => 'Villa',
        'apartment'    => 'Apartment',
        'other'  => 'Other',        
    );
    
    // Sort
    ksort($address_fields['address_2']['options']);

    return $address_fields;
}

我使用上面的代码来制作下拉菜单。

【问题讨论】:

    标签: wordpress woocommerce drop-down-menu


    【解决方案1】:

    我从这个https://stackoverflow.com/a/47015385/12536243得到它

    如果有人想使用地址_2,这里是代码

    // Change "address"  to a dropdown
    add_filter( 'woocommerce_default_address_fields' , 'override_address_2_dropdown' );
    function override_address_2_dropdown( $address_fields ) {
    
        // Define here in the array your desired name 
        $option_unit_type = array(
             '' => __( 'Select unit type' ),
            'villa' => 'Villa',
            'apartment' => 'Apartment',
            'other' => 'Other',
        );
    
        $address_fields['address_2']['type'] = 'select';
        $address_fields['address_2']['options'] = $option_unit_type;
    
    
        return $address_fields;
    }
    

    【讨论】:

      【解决方案2】:

      在选择框中占位符是第一个空白选项。

      add_filter( 'woocommerce_default_address_fields' , 'address2_dropdown' );
      
      function address2_dropdown( $address_fields ) {
      
          // address_2
          $address_fields['address_2']['type'] = 'select';
          $address_fields['address_2']['options'] = array(
              '' => 'Address',
              'villa' => 'Villa',
              'apartment'    => 'Apartment',
              'other'  => 'Other',        
          );
      
          // Sort
          ksort($address_fields['address_2']['options']);
      
          return $address_fields;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-03-16
        • 2021-04-07
        • 2020-03-06
        • 2015-06-27
        • 2017-07-23
        • 2015-07-19
        • 2016-04-08
        相关资源
        最近更新 更多