• Resolved mike62

    (@mike62)


    I have a site using WooCommerce. I’ve added a checkbox to the registration form here, for subscribing to a newsletter:
    https://www.hilarydruxman.com/my-account/

    Is it possible, when the form is submitted to check to see if that newsletter checkbox is selected, and if it is, send the email address to a 3rd-party service? I’m using Sendy.

    Thanks!

    Here’s the code I’m using to add the checkbox (in functions.php):

    add_filter( 'register_form', 'adding_custom_registration_fields' );
    function adding_custom_registration_fields( ) {
    	echo '<div class="form-row form-row-wide"><label for="reg_subscribe"><input type="checkbox" name="reg_subscribe" id="reg_subscribe" value="'.esc_attr($_POST['is_subscribed']).'" />Subscribe to the newsletter</label></div>';
    }
Viewing 1 replies (of 1 total)
  • Thread Starter mike62

    (@mike62)

    I got it working with some jQuery. The below code needs to be added to functions.php:

    add_filter( 'register_form', 'adding_custom_registration_fields' );
    function adding_custom_registration_fields( ) {
    
    	echo '<div class="form-row form-row-wide"><label for="reg_subscribe"><input type="checkbox" name="reg_subscribe" id="reg_subscribe" value="" />Subscribe to the newsletter</label></div>';
    
    		// email of the person being added to the email list
    		$sendy_email = $_POST['email'];
    
    		$url = "https://www.yourdomain.com/sendy/subscribe/$sendy_email/1/";
    		?>
    <script>
    	jQuery( ".register" ).submit(function() {
    		var user_email = jQuery("#reg_email").val();
    
    		if(jQuery('#reg_subscribe').is(':checked')) {
    		  jQuery.post( "https://www.hilarydruxman.com/sendy/subscribe/"+ user_email +"/1/" );
    		}
    </script>
    
    <?php
    }

    Note that you need to change “yourdomain” to your domain, and the “1” at the end of that URL is the id for the list you want to subscribe the user to.

Viewing 1 replies (of 1 total)
  • The topic ‘Capturing an email address from the front-end registration form’ is closed to new replies.