Add Products to Ubercart Hack

Here's a little hack that will enable you to add products to Ubercart by passing an array of product ID's and quantity of each product specified. Relies solely on the uc_cart_add_item(); function. Works great in content nodes that you've enabled PHP input on.


<?php
if(!empty($_POST['products'])){
$products = $_POST['products'];

foreach($products as $product){
if($product['qty'] != 0){

$pid = $product['pid'];
$qty = $product['qty'];

//uc_cart_add_item(2, 3);
}
}
}
?>

Example Input Form

Product
Qty.

2 Pack

4 Pack

12 Pack

75 Pack

Have fun with this.