• ewraniwego

    (@ewraniwego)


    Hello,

    I would like to organize several giveways on my site but I would like that if a user has already participated in a giveway, he can’t participate in the other giveways. Is it possible to automatically block a user’s email address after his email has already been used?
    Is this possible in PHP for example from the functions.php?

    Thanks a lot!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Igor Benic

    (@ibenic)

    Hi @ewraniwego, that’s a premium feature, where you can decide on how many giveaways can 1 email register to.

    A simplified code:

    
    add_action( 'sg_process_registration', 'ewraniwego_block_email_from_multiple_giveaways' );
    
    function ewraniwego_block_email_from_multiple_giveaways( $front ) {
      global $wpdb;
      
       $email = isset( $front->posted_data['sg_form']['user_email'] ) ? $front->posted_data['sg_form']['user_email'] : false;
    
       if ( ! $email ) {
         $front->add_error( 'no-email', __( 'No Email Provided', 'your_textdomain' ) );
         return false;
       }
    
    	$count = $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM ' . $wpdb->giveasap_entries . ' WHERE email = %s', $email ) );
    
       if ( absint( $count ) ) {
         $front->add_error( 'max-met', __( 'You are already signed up to a giveaway', 'your_textdomain' ) );
    		return false;
    	}
    
    	return true;
    }
    
    • This reply was modified 2 years ago by Igor Benic.
    Thread Starter ewraniwego

    (@ewraniwego)

    Hi @ibenic, Thank you for your answer. It works perfectly on my site. Thank you very much.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘automatically block emails from users’ is closed to new replies.