When developing a custom e-commerce site for a client recently, I ran into a huge issue with WP E-Commerce. There’s NO WAY to easily add multiple items to their shopping cart, at once!
Well, you’re looking for a solution to adding multiple items to a shopping cart with WP E-Commerce, here’s an ajax solution:
var function_callback = function(result) {
// callback code goes here
}
function add_item_to_cart(product_id,quantity) {
/* set default for product quantity to 1 */
if(!quantity){ quantity = 1 }
/* query string to send wordpress to tell it to add these options to the cart */
var data = "custom_text=&wpsc_quantity_update="+ quantity +"&key=-1&wpsc_update_quantity=true&wpsc_ajax_action=add_to_cart&product_id="+ product_id +"&is_customisable=true";
/* uses custom function from WP E-Commerce to update cart with ajax */
ajax.post('index.php?ajax=true', function_callback, data);
}
To use the code above, all you need to do is send the function add_item_to_cart the product_id and the quantity of that product. With some Ajax/Wordpress/WP E-Commerce magic, you will have your shopping cart automatically updated.
And…. that’s it! You can now call this function at will, at any time. Please, feel free to ask me any questions about this product in the comments!
Posted via email from Scott Corgan | Comment »