samedi 7 mai 2016

Woocommerce select delivery points from DataBase

I am trying to create 2 select box on billing card with delivery points. In first select box user will be able to choose city, and in second select box he will be able to choose delivery point in that city. I was thinking to load data from mysql db, but I am not sure how to do it. First question is how to assign a change event of woocommerce select field? And second how to correctly code it?

PHP script:

<!DOCTYPE html>
<html>
<head>

</head>
<body>
 <?php
$res = mysqli_connect('localhost','...','...','...');
if (!$res) {
    die('Could not connect: ' . mysqli_error($res));
}
mysqli_select_db($res,"wp_cities");
$sqli="SELECT * FROM wp_cities";
$result = mysqli_query($res,$sqli);
if(mysql_num_rows($result) > 0) {
    while($r = mysql_fetch_assoc($res)) {
        echo $r['City'];
   
    }

}

?> 
<?php
$q = intval($_GET['q']);

$con = mysqli_connect('localhost','...','...','...');
if (!$con) {
    die('Could not connect: ' . mysqli_error($con));
}

mysqli_select_db($con,"wp_points");
$sql="SELECT * FROM wp_points WHERE Id = '".$q."'";
$result = mysqli_query($con,$sql);

while($row = mysqli_fetch_array($result)) {
    echo $row['Adress'];
}

mysqli_close($con);
?>
</body>
</html>

WordPress function.php:

$fields['billing']['billing_qqq'] = array(
        'label'     => __('Points', 'woocommerce'),
    'placeholder'   => _x('qqq', 'placeholder', 'woocommerce'),
    'required'  => false,
    'class'     => array('form-row-wide'),
    'clear'     => true,
        'type' => select,
        'options' => array( 
  'option_1' => 'London',
  'option_2' => 'Moscow'
)     ); 


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire