• Hello friends

    I would like to create a drop down list “select field” with time values.

    I would like that it would only show the current time as the first value, and Until. 02:00.

    I have here a small example, but here I manualt typed all times, so it is not dynamic.

    Hope you can help me .. Thanks in advance ??

    ——————-
    date_default_timezone_set(‘Europe/Copenhagen’);
    $day = date(‘N’);
    $time = date(‘H.i’);

    $fields[‘shipping’][‘shipping_company’] = array(
    ‘type’ => ‘select’,
    ‘label’ => __(‘Deliverytime’, ‘woocommerce’),
    ‘required’ => false,
    ‘class’ => array(‘form-row-wide’),
    ‘clear’ => true,
    ‘options’ => array(
    ‘11.00’ => __(‘11.00’, ‘woocommerce’),
    ‘11.15’ => __(‘11.15’, ‘woocommerce’),
    ‘11.30’ => __(‘11.30’, ‘woocommerce’),
    ‘11.45’ => __(‘11.45’, ‘woocommerce’),
    ‘12.00’ => __(‘12.00’, ‘woocommerce’),
    ‘12.15’ => __(‘12.15’, ‘woocommerce’),
    ‘12.30’ => __(‘12.30’, ‘woocommerce’),
    ‘12.45’ => __(‘12.45’, ‘woocommerce’),
    ‘13.00’ => __(‘13.00’, ‘woocommerce’),
    ‘13.15’ => __(‘13.15’, ‘woocommerce’),
    ‘13.30’ => __(‘13.30’, ‘woocommerce’),
    ‘13.45’ => __(‘13.45’, ‘woocommerce’),
    ‘14.00’ => __(‘14.00’, ‘woocommerce’),
    ‘14.15’ => __(‘14.15’, ‘woocommerce’),
    ‘14.30’ => __(‘14.30’, ‘woocommerce’),
    ‘14.45’ => __(‘14.45’, ‘woocommerce’),
    ‘15.00’ => __(‘15.00’, ‘woocommerce’),
    ‘15.15’ => __(‘15.15’, ‘woocommerce’),
    ‘15.30’ => __(‘15.30’, ‘woocommerce’),
    ‘15.45’ => __(‘15.45’, ‘woocommerce’),
    ‘16.00’ => __(‘16.00’, ‘woocommerce’),
    ‘16.15’ => __(‘16.15’, ‘woocommerce’),
    ‘16.30’ => __(‘16.30’, ‘woocommerce’),
    ‘16.45’ => __(‘16.45’, ‘woocommerce’),
    ‘17.00’ => __(‘17.00’, ‘woocommerce’),
    ‘17.15’ => __(‘17.15’, ‘woocommerce’),
    ‘17.30’ => __(‘17.30’, ‘woocommerce’),
    ‘17.45’ => __(‘17.45’, ‘woocommerce’),
    ‘18.00’ => __(‘18.00’, ‘woocommerce’),
    ‘18.15’ => __(‘18.15’, ‘woocommerce’),
    ‘18.30’ => __(‘18.30’, ‘woocommerce’),
    ‘18.45’ => __(‘18.45’, ‘woocommerce’),
    ‘19.00’ => __(‘19.00’, ‘woocommerce’),
    ‘19.15’ => __(‘19.15’, ‘woocommerce’),
    ‘19.30’ => __(‘19.30’, ‘woocommerce’),
    ‘19.45’ => __(‘19.45’, ‘woocommerce’),
    ‘20.00’ => __(‘20.00’, ‘woocommerce’),
    ‘20.15’ => __(‘20.15’, ‘woocommerce’),
    ‘20.30’ => __(‘20.30’, ‘woocommerce’),
    ‘20.45’ => __(‘20.45’, ‘woocommerce’),
    ‘21.00’ => __(‘21.00’, ‘woocommerce’),
    ‘21.15’ => __(‘21.15’, ‘woocommerce’),
    ‘21.30’ => __(‘21.30’, ‘woocommerce’),
    ‘21.45’ => __(‘21.45’, ‘woocommerce’),
    ‘22.00’ => __(‘22.00’, ‘woocommerce’),
    ‘22.15’ => __(‘22.15’, ‘woocommerce’),
    ‘22.30’ => __(‘22.30’, ‘woocommerce’),
    ‘22.45’ => __(‘22.45’, ‘woocommerce’),
    ‘23.00’ => __(‘23.00’, ‘woocommerce’),
    ‘23.15’ => __(‘23.15’, ‘woocommerce’),
    ‘23.30’ => __(‘23.30’, ‘woocommerce’),
    ‘23.45’ => __(‘23.45’, ‘woocommerce’),
    ‘00.00’ => __(‘00.00’, ‘woocommerce’),
    ‘00.15’ => __(‘00.15’, ‘woocommerce’),
    ‘00.30’ => __(‘00.30’, ‘woocommerce’),
    ‘00.45’ => __(‘00.45’, ‘woocommerce’),
    ‘01.00’ => __(‘01.00’, ‘woocommerce’),
    ‘01.15’ => __(‘01.15’, ‘woocommerce’),
    ‘01.30’ => __(‘01.30’, ‘woocommerce’),
    ‘01.45’ => __(‘01.45’, ‘woocommerce’),
    ‘02.00’ => __(‘02.00’, ‘woocommerce’)));
    return $fields;
    }

Viewing 1 replies (of 1 total)
  • hi.. i figured this out yesterday. like you, I was looking for a solution and found none. hope this helps in a way.. here’s how to do it dynamically.

    /*override fields*/
    // Hook in
    add_filter( 'woocommerce_checkout_fields' , 'override_checkout_fields' );
    
    // Our hooked in function - $fields is passed via the filter!
    function override_checkout_fields( $fields ) {
    
    //place select code here
    $fields['billing']['billing_company']['placeholder'] = 'Enter Company Name';
    $fields['billing']['billing_company'] = array(
    
        'required'  => true,
        'label' => 'Company Name',
        'class'     => array('form-row-wide'),
        'clear'     => true,
        'type'      => 'select',
         'options'     => select_list()/*array(
    
            )*/ //end of options
    
         );
    
    return $fields;
    }
    
    function select_list(){
    
    //set sql statements
    
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "wordpress";
    
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
        $sql = "SELECT company_name FROM wp_company_list";
    $result = $conn->query($sql);
    
    $option_values = array();//prepare our array variable
    
      if ($result->num_rows > 0) {
        $start = 0;
        while($row = $result->fetch_assoc()) {
              $option_values[$row['company_name']] = __($row['company_name'],'woocommerce');
              $start++;
        }//end while
      }//end if
    
    return $option_values;
    }//end function select_list

    i used “custom database table” plugin to create a phpmyadmin table for company names. (although you can directly do that in the database. i just wanted a database table plugin visible in the wordpress backend for my client). then i simply created a function that generates the values for the select field.

Viewing 1 replies (of 1 total)
  • The topic ‘Help! add a loop to Woocommerce select checkout field.’ is closed to new replies.