returning the two custom fields works perfectly the way you described.
I am not successful in setting the shipping_id though. This is what I have:
<?php
Include ("databaselogin.php");
$app =& JFactory::getApplication();
$order = $app->getUserState( HIKASHOP_COMPONENT.'.checkout_fields',null);
//get the customer's villa name
$thevilla = $order->co_villa;
$addonorder = $order->co_addon;
if ($addonorder)
{
$deliveryarea = 3;
}
else
{
$theSQL = "SELECT ib_villas.villa_deliverylocation
FROM jos_hikashop_zone INNER JOIN ib_villas ON jos_hikashop_zone.zone_id = ib_villas.villa_zone
WHERE (((jos_hikashop_zone.zone_type)='ship') AND ((jos_hikashop_zone.zone_namekey)= '" . $thevilla . "'))";
$query = mysql_query($theSQL);
while ($result = mysql_fetch_array($query)) {
$deliveryarea = $result["villa_deliverylocation"];
}
}
// the following line successfully returns a 1,2,or 3
echo $deliveryarea;
// the following lines do not set the shipping_id to 1,2, or 3
$app =& JFactory::getApplication();
$app->setUserState( HIKASHOP_COMPONENT.'.shipping_id',$deliveryarea);
?>
it is the last line that I'm having the issue with:
$app->setUserState( HIKASHOP_COMPONENT.'.shipping_id',$deliveryarea);
Note, its not necessary for the shipping choices to actually show, as long as the shipping is adjusted before the credit card is processed.