WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have built a flash application where a user can customise a product. I currently have an 'add to basket' button within the flash application that doesn't do anything. I'd like it to add a product to the basket when clicked.

Writing a flash function with event clicks is no problem, but I'm not sure how to connect to the shopping basket and would appreciate any advice on how to do this.

It appears to be done in AJAX but I'm not confident in this. Any help would be greatly appreciated.

Thank you



Thanks Milo. Once I understand how to invoke the existing "function wpsc_add_to_cart()" I'll try to make it more efficient and implement what you have suggested, but at the moment I'm struggling to invoke the existing one from within flash.

I've determined the JQuery I need to call from within Flash is the one below, but I don't know how to call it (it doesn't appear to have a function name like I'm used to seeing):

// Submit the product form using AJAX
jQuery("form.product_form").live('submit', function() {
    // we cannot submit a file through AJAX, so this needs to return true to submit the form normally if a file formfield is present
    file_upload_elements = jQuery.makeArray(jQuery('input[type=file]', jQuery(this)));
    if(file_upload_elements.length > 0) {
        return true;
    } else {
        form_values = jQuery(this).serialize();
        // Sometimes jQuery returns an object instead of null, using length tells us how many elements are in the object, which is more reliable than comparing the object to null
        if(jQuery('#fancy_notification').length == 0) {
            jQuery('div.wpsc_loading_animation',this).css('visibility', 'visible');
        jQuery.post( 'index.php?ajax=true', form_values, function(returned_data) {
            jQuery('div.wpsc_loading_animation').css('visibility', 'hidden');

            if(jQuery('#fancy_notification') != null) {
                jQuery('#loading_animation').css("display", 'none');
            //jQuery('#fancy_notificationimage').css("display", 'none');

        return false;

Any ideas how to call this JQuery from within Flash?

Thanks for your help so far

share|improve this question

this is a simple function that will add an item to the cart. you could tie this to an ajax call and pass whatever POST vars you want, obviously product id, quantity, etc..

function my_add_to_cart(){

    global $wpsc_cart;
    $product_id = 1;
    $args = array();
    $args['quantity'] = 1;
    $args['variation_values'] = null;
    $args['provided_price'] = null;
    $args['comment'] = null;
    $args['time_requested'] = null;
    $args['custom_message'] = null;
    $args['file_data'] = null;
    $args['is_customisable'] = false;
    $args['meta'] = null;
    $state = $wpsc_cart->set_item( $product_id, $args );

share|improve this answer
Thanks Milo. I'm trying to make sure I've understood this correctly... this code doesn't go in the flash file? it goes in it's own php file which flash should activate? I was thinking before that I could try and tap into the code that is already there (replicate the existing buttons submit actions and values?) – Dean Rowe Aug 13 '11 at 13:34
this would be a php function that would go in your theme's functions.php or a plugin. your Flash app would call a javascript function, which would then invoke this function via AJAX. This is basically a very simplified version of the actual function WPeC uses, but WPeC does AJAX in a bad way that uses a lot more memory, it's better to look on this site for examples of proper use of AJAX in WP. – Milo Aug 13 '11 at 14:47
edited original question as too much to fit in comment box. – Dean Rowe Aug 13 '11 at 15:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.