geraldpasion
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
Hi Ewout,
$item[‘product_id’] worked! but how about the other elements like product description? is there any list of elements i can put into $item[] to get specific data? Thanks so much!
Forum: Plugins
In reply to: Help! add a loop to Woocommerce select checkout field.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 2 replies - 1 through 2 (of 2 total)