1

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.

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());
});
3
  • 1
    You will need AJAX to make a POST request without refreshing the page, so send the registration form via AJAX and on success submit the cart form Commented Jul 3, 2013 at 6:12
  • Thanks, helped me go in the right direction Commented Jul 3, 2013 at 17:28
  • You don't necessarily need AJAX, you could also submit the forms into iFrames using the 'target' attribute. However, if/since you don't have any fileuploads, AJAX is the better way to go. Commented Jul 3, 2013 at 17:33

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.