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());
});
4

1 回答 1

0

另一种方法是使用像shopp_cart_add_item这样的钩子并在那里进行 wp-registration。

我个人会在成功购买后稍后触发 wp-registration。现在,当您的客户从购物车中删除课程时,wp-registration 已经发生。

于 2015-05-26T11:10:14.010 回答