Submitting multiple forms with jQuery for WordPress Registration

I’m working on an e-commerce site (shopp) where there are products that are subscription based. There are inputs for the users name and email when purchasing the product.

The customer wants the users who purchase this product to be registered as subscribers in WordPress. So what I’m trying to do is grab the email value from that and use their email as username and email to register in WordPress. I was able to get the registration part to work, but not sure how to get both forms to submit properly. Right now it will just submit the registration form, ignoring the add to cart product form.

Read More

cart form:

<form action="<?php shopp('cart','url'); ?>" method="post" class="shopp product validate validation-alerts">
    <!-- extra code -->
    <?php
    if ( shopp( 'product', 'in-category', 'id=32' ) ) : // courses ?>
        <div id="guests" class="guests">
            <div>Enter the names and emails of the people subscribing</div>
            <div class="guest-list">
                <p class="guest">
                    <label>First Name </label><?php shopp('product','input',"name=First Name 1"); ?><br />
                    <label>Last Name </label><?php shopp('product','input',"name=Last Name 1"); ?><br />
                    <label>Email </label><?php shopp('product','input',"name=Email 1"); ?>
                </p>
            </div>
            <?php shopp('product', 'addtocart'); ?>
        </div>
        <?php
    else :
        shopp('product', 'addtocart');
    endif;
    ?>
    <?php wp_nonce_field('check-user', '_check-user-nonce', true, true); ?>
</form>

register form:

<form id="register-form" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" method="post">
    <input type="hidden" name="user_login" value="Username" id="user_login" class="input" />
    <input type="hidden" name="user_email" value="E-Mail" id="user_email" class="input"  />
    <?php do_action('register_form'); ?>
    <input type="hidden" value="Register" id="register" />
</form>

jquery:

(function ($) {
    $('#guests').on('click', '.addtocart', function() {
        var id = $('.product-qty-wrapper').attr('id'),
            userEmail = $('#data-email-1-'+ id).val();

        // take users email and use for register form
        $('#register-form input[name="user_login"]').val(userEmail);
        $('#register-form input[name="user_email"]').val(userEmail);
        $('#register-form').submit();
    });
}(jQuery));

update

found this post which worked for me submitting multiple forms with AJAX

$('form').each(function() {
    var $this = $(this);
    $.post($this.attr('action'), $this.serialize());
});

Related posts

Leave a Reply

1 comment

  1. Another way would be to use a hook like shopp_cart_add_item and do the wp-registration there.

    I personally would trigger the wp-registration at a later point after a successful purchase. Right now when your customer removes the course from the cart, the wp-registration has already taken place.