• Resolved jlalonde

    (@jlalonde)


    Hi,

    I’m trying to edit the plugin edd-auto-register.php in order to restrict its action to only one product (the one with ID 80). I checked with EDD and there is no filter that would allow it at this time.

    So, I’m trying to edit the plugin PHP but I’m having a hard time just finding how to make this work. Maybe there is a syntax error that I’m missing or it is because how the way EDD plugins are updated or cached. Please, could you help me with this?

    Here is what I’ve done:

    1) Plugin was installed and working well (v1.3.13). Disable the plugin.

    2) Edit the file edd-auto-register.php by adding these 5 lines changes:

    (adding from line 380)

    public function create_user( $payment_data = array(), $payment_id = 0 ) {
    
    	// First line added - Return false if product is excluded
    	$download_id = $my_download->get_ID();
    	if ( $download_id <> 80  ) {
    		return false;
    	}
    
    	// User account already associated
    

    … remaining code without changes

    3) Activate the plugin and flush the server cache.

    4) Make sure the email address used to test the transaction is not user (delete user from previous test).

    5) Make the transaction that should register the user buying the product id 80.

    Then the payment form returns the message

    “Unable to complete your request. Please try again.”

    To be able to complete a transaction, I have to:

    1) Desactivate the plugin.
    2) Revert the changes (remove the 5 lines above).
    3) Activate the plugin.
    4) Complete the transaction.

    Then, the user is added, email sent, etc.

    Do you see a PHP syntax error? Or an error in my procedure? Any help appreciated.

    Thanks,

    Jean

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jlalonde

    (@jlalonde)

    Doing more test on this, I first focussed on making sure I’m getting the product ID. I tried these two methods to get the ID (and did nothing about aborting the auto-register action).

    I found two methods. The first command suggested to me:

    $download_id1 = $my_download->get_ID();

    produces an error “Unable to complete your request. Please try again.”

    A friend suggested to try this:

    $download_id2 = $payment_data['cart_details']['id'];

    In this case it returns an empty string (but no error).

    Any other suggestion on how to retrieve the product id from the auto-register plugin?

    Thread Starter jlalonde

    (@jlalonde)

    Finally, this is working:

    // Return if product excluded
    $download_id = $payment_data['downloads'][0]['id'];
    if ( $download_id !== 80 ?) {
    return false;
    }

    If a buyer can buy more than one item at the time, this would need to be reviewed in order to check all products in the $payment_data[‘downloads’] array but, for my needs, this is OK for now.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Editing the EDD-Auto-Register plugin’ is closed to new replies.