복붙노트

[WORDPRESS] WooCommerce에서 조건부로 unse 체크 아웃 필드를 unse

WORDPRESS

WooCommerce에서 조건부로 unse 체크 아웃 필드를 unse

해결법


  1. 1.

     function bs_filter_checkout_fields($fields){ 
                         $fields['billing'] = array(
                              'add_type' => array(
                                    'type' => 'radio',
                                    'label' => __( 'Address Type' ),
                                    'options' => array( 'house' => __( 'House' ), 'building' => __( 'Building' ), 'office' => __( 'Office' ) ),
                                    'required' => true
                                    ),
                                'add_house_name' => array(
                                    'type' => 'text',
                                    'required'      => true,
                                    'placeholder' => __( 'House Name/Number' ),
                                    'label' => __( 'House Name/Number' )
                                    ),
                                'add_building_name' => array(
                                    'type' => 'text',
                                    'required'  => true,
                                    'placeholder' => __( 'Building Name/Number' ),
                                    'label' => __( 'Building Name/Number' )
                                    ),
                                'add_office_name' => array(
                                    'type' => 'text',
                                    'required'  => true,
                                    'placeholder' => __( 'Office Name/Number' ),
                                    'label' => __( 'Office Name/Number' )
                                    ),
                                );
            if( true ){ // pass conditional statement here
              unset($fields['billing']['add_house_name']);  //  remove field
              $fields['billing']['add_building_name']['required']   = false; // remove required validation
            }                   
            return $fields;
            }
    
  2. from https://stackoverflow.com/questions/37099213/conditionally-unset-checkout-field-in-woocommerce by cc-by-sa and MIT license