Okay,
Currently my code always adds just one item to my shopping basket at a time, which is completely fine for most items. However there are a few items that are in multiples, and are therefore only available in quantities of 5, 10 and 20. I have altered my code slightly so that when looking in the basket customers can change the quantities solely to these amounts but have a problem as when the basket page is opened the quantity always defaults to 1 item, even though it may show in the basket as 5. It is then necessary to click the ‘Update Cart’ button to refresh the amount. My question then is thus: what can I add to the script so that the update cart function is run as soon as the page loads? As this to me seems like the easiest way to do it.
This is my script below. I want the mutliple items to default to the value of $multi1a and not to $qty (as when the page loads $qty will always be the value of 1)
$output[] = '<td><select name="qty'.$id.'" value="'.$qty.'"><option selected value="'.$multi1a.'">'.$multi1a.'</option><option value="'.$multi2a.'">'.$multi2a.'</option><option value="'.$multi3a.'">'.$multi3a.'</option></td>';
}
if ($pricing == "Multi")
{
if ($qty == $multi1a) {
$output[] = '<td>£'.($multi1b).'</td>';
$total += ($multi1b);
}
if ($qty == $multi2a) {
$output[] = '<td>£'.($multi2b).'</td>';
$total += ($multi2b);
}
if ($qty == $multi3a) {
$output[] = '<td>£'.($multi3b).'</td>';
$total += ($multi3b);
}
}
else {
$output[] = '<td>£'.(($Price) * $qty).'</td>';
$total += ($Price) * $qty;
}
$output[] = '</tr>';
}
$sum = array_sum($contents);
$output[] = '</table>';
$output[] = '<p>Grand total: <strong>£'.$total.'</strong></p>';
$output[] = '<div><button type="submit">Update cart</button></div>';
$output[] = '</form>';
Thanks!!