Support » Plugin: Restrict User Access - Membership & Content Protection » API – Adding an user based on woocommerce order status (paied)

  • Resolved tecladigital

    (@tecladigital)


    Hello Joachim Jensen

    Nice plugin, congratulations.

    I repeat here my question that I insert on this resolved topic: Automation of adding user access after WooCommerce order finalization

    Can you show me how to do similar, but just when the status of the order changes to processing or complete. I don’t want to add the user if the order is on Pending payment status.

    Better than this, could be an Add-on for that.

    Thank you for your nice plugin.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter tecladigital

    (@tecladigital)

    I found part of the answer changing the line add_action( ‘woocommerce_thankyou’, function( $order_id ) { to add_action( ‘woocommerce_order_status_processing’, function( $order_id ) {

    Ok. But I set the access level for one day on a user some days ago, and after I make one other order, the user is added repeated and not assuming the new duration.

    How can I update the duration with that code iff the user already on the user level?

    Thank you.

    Thread Starter tecladigital

    (@tecladigital)

    One more solved by myself (I put here to help someone whit this problem):

    I add $user->remove_level($level_id); before $user->add_level($level_id);

    This way iff the user already on the level, it will be deleted.

    Now I will try to find a way iff user exist, just extend the expiration.

    If someone could help me with this, I appreciate it.

    Thank you.

    Thread Starter tecladigital

    (@tecladigital)

    I don’t know but maybe the author can tell us:

    It’s not possible to extend the Duration for one user because duration is attached to the Level. Correct?

    This way if one user “buy one more subscription” (buying once more the product) before ending the subscription he will lose the time left. Because the new subscription will start at that moment.

    Plugin Author Joachim Jensen

    (@intoxstudio)

    Thank you for following up with your posts.

    Currently there is no API to extend levels, though it is on the roadmap. You can modify a user’s level expiry directly like this:

    
    //set expiry to "now"
    update_user_meta($user_id, '_ca_level_expiry_'.$level_id, time());
    
    //add 24h to existing expiry
    $user = rua_get_user();
    if($user->has_level($level_id)) {
        update_user_meta($user_id, '_ca_level_expiry_'.$level_id, $user->levels()->get($level_id)->get_expiry() + 86400);
    }
    

    I hope this helps!

    Thread Starter tecladigital

    (@tecladigital)

    Thank you. I will tray this solution.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘API – Adding an user based on woocommerce order status (paied)’ is closed to new replies.