在Thickbox中提交表单,然后关闭窗口

I am using the Woocommerce plugin on my Wordpress site. When you click on a product, it loads a Thickbox iframe window where you input the quantity and add it to the cart. You can view the test site here: http://75.103.92.37/rent-storage/

I'd like to have the form submit the data to the shopping cart, then close the window. This link is the closest solution I've found, but works using a "thank you" page which I do not have and would like to avoid using if possible.

This is my form code. I placed an OnSubmit function to close the Thickbox window. It works, but the form does not submit.

    <form class="cart" method="post" enctype='multipart/form-data' onsubmit="javascript:parent.eval('tb_remove()')">

    <?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>

    <input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->id ); ?>" />

    <?php
    if ( ! $product->is_sold_individually() )
        woocommerce_quantity_input( array(
            'min_value' => apply_filters( 'woocommerce_quantity_input_min', 1, $product ),
            'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->backorders_allowed() ? '' : $product->get_stock_quantity(), $product )
    ) );
    ?>

    <button type="submit" class="button alt"><?php echo $product->single_add_to_cart_text(); ?></button>

    <?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>

</form>

Thank you for your help!

tb_remove() returns false so the form would not submit.

You need to add a click handler to "Add to Cart" that runs tb_remove() and also returns true.

Since you're submitting the form in an iframe, you need to make sure the "post" fires before removing the iframe from the document.

For usability, it would be nice to also have a message saying your product was added to the cart when the thickbox closes.