【问题标题】:Add new fields at the billing address woocommerce在帐单地址 woocommerce 中添加新字段
【发布时间】:2016-06-09 14:57:05
【问题描述】:

我想在我的网站上编辑我的帐单地址,我需要在我的帐户页面中添加删除一些其他的,我应该编辑哪个代码?

在此感谢您

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    您能否检查以下代码,您可以添加新的自定义字段示例。

    add_filter( 'woocommerce_billing_fields', 'custom_woocommerce_billing_fields' );
    
    function custom_woocommerce_billing_fields( $fields ) {
    
       $fields['billing']['billing_options'] = array(
        'label'       => __('Custom Field', 'woocommerce'),             // Add custom field label
        'placeholder' => _x('Custom Field', 'placeholder', 'woocommerce'),  // Add custom field placeholder
        'required'    => false,             // if field is required or not
        'clear'       => false,             // add clear or not
        'type'        => 'text',                // add field type
        'class'       => array('own-css-name')      // add class name
        );
    
     return $fields;
    }
    

    【讨论】:

    【解决方案2】:

    删除现有字段,例如国家/地区:

    add_filter( 'woocommerce_billing_fields' , 'custom_override_billing_fields' );
    function custom_override_billing_fields( $fields ) {
      unset($fields['billing_country']);
      return $fields;
    }
    

    【讨论】:

      【解决方案3】:

      也许是使用woocommerce_default_address_fields 的最佳方式- 是吗? 例如作为 #5447232

      
      add_filter( 'woocommerce_default_address_fields', 'add_MyNewOption_address' );
      
      function add_MyNewOption_address( $fields ) {
      
         $fields['MyNewOption'] = array(
          'label'       => __('Custom Field', 'woocommerce'),             // Add custom field label
          'placeholder' => _x('Custom Field', 'placeholder', 'woocommerce'),  // Add custom field placeholder
          'required'    => false,             // if field is required or not
          'clear'       => false,             // add clear or not
          'type'        => 'text',                // add field type
          'class'       => array('own-css-name')      // add class name
          );
      
       return $fields;
      }
      
      
      

      【讨论】:

        猜你喜欢
        • 2017-08-31
        • 2021-06-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-08
        • 2015-07-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多