Creating a Woocommerce custom shipping method as a select field


I’m working with thw WooCommerce plugin for WordPress. My main goal right now is to create a custom shipping method. So far I’ve managed to create this method and display the same in my billing form. The problem is that this shipping methods are checkbox by default and I want an extra funcionality: Display a select with a series of options as soon a I select this custom shipping method on the billing order form.

This next class handles the custom shipping method:

/**  * WC_Shipping_Pickup class.  *  * @class       WC_Shipping_Pickup  * @version     1.0.0  * @package     Shipping-for-WooCommerce/Classes  * @category    Class  * @author      Pickup Softwares  */ class WC_Shipping_Pickup extends WC_Shipping_Method {     public function __construct($  instance_id = 0)     {         $  this->id                    = 'pickup_method';         $  this->instance_id           = absint($  instance_id);         $  this->method_title          = __('Pickup');         $  this->method_description    = __('Método de envío: punto de pickup');         $  this->supports              = array(             'shipping-zones',             'instance-settings',         );          $  this->instance_form_fields = array(             'enabled' => array(                 'title'         => __('Habilitar/Deshabilitar'),                 'type'          => 'checkbox',                 'label'         => __('Habilitar este método de envío'),                 'default'       => 'yes',             ),             'title' => array(                 'title'         => __('Título'),                 'type'          => 'text',                 'description'   => __('Título que se visualizará en el formulario de facturación'),                 'default'       => __('Pickup'),                 'desc_tip'      => true             )         );          $  this->enabled              = $  this->get_option('enabled');         $  this->title                = $  this->get_option('title');          add_action('woocommerce_update_options_shipping_' . $  this->id, array( $  this, 'process_admin_options' ));     }      public function calculate_shipping($  package = array())     {         $  this->add_rate(array(             'id'    => $  this->id . $  this->instance_id,             'label' => $  this->title,             'cost'  => 0,         ));     }      /**      * Generate Select HTML.      *      * @param string $  key Field key.      * @param array  $  data Field data.      * @since  1.0.0      * @return string      */     public function generate_select_html()     {         $  token = null;         $  expire = null;         $  token = qk_login($  token, $  expire);          $  agencies = qk_agencies($  token);          $  field_key = $  this->get_field_key('_pickups');          $  options = [];         foreach ($  agencies as $  agency) {             $  options[$  agency->id] = $  agency->detalle;         }          $  defaults  = array(             'title'             => 'Pickups',             'disabled'          => false,             'class'             => '',             'css'               => '',             'placeholder'       => 'Seleccionar punto de recogida',             'type'              => 'text',             'desc_tip'          => false,             'description'       => '',             'custom_attributes' => array(),             'options'           => $  options,         );          $  data = wp_parse_args($  data, $  defaults);          ob_start(); ?>         <tr valign="top">             <th scope="row" class="titledesc">                 <label for="<?php echo esc_attr($  field_key); ?>"><?php echo wp_kses_post($  data['title']); ?> <?php echo $  this->get_tooltip_html($  data); // WPCS: XSS ok.?></label>             </th>             <td class="forminp">                 <fieldset>                     <legend class="screen-reader-text"><span><?php echo wp_kses_post($  data['title']); ?></span></legend>                     <select class="select <?php echo esc_attr($  data['class']); ?>" name="<?php echo esc_attr($  field_key); ?>" id="<?php echo esc_attr($  field_key); ?>" style="<?php echo esc_attr($  data['css']); ?>" <?php disabled($  data['disabled'], true); ?> <?php echo $  this->get_custom_attribute_html($  data); // WPCS: XSS ok.?>>                         <?php foreach ((array) $  data['options'] as $  option_key => $  option_value) : ?>                             <option value="<?php echo esc_attr($  option_key); ?>" <?php selected((string) $  option_key, esc_attr($  this->get_option($  key))); ?>><?php echo esc_attr($  option_value); ?></option>                         <?php endforeach; ?>                     </select>                     <?php echo $  this->get_description_html($  data); // WPCS: XSS ok.?>                 </fieldset>             </td>         </tr>         <?php          return ob_get_clean();     } } 

I’ve been trying to use this generate_select_html function to generate this select input but I’m actually running with my eyes closed because I don’t know if this is right way to do things. That piece of code causes an infinite loading page on the billing form so it is wrong (obviusly). Is there a way to adchieve what I want?