I would like to programatically renew memberships when a transaction has been completed in Woocommerce.
I want my members to have a more consistent experience and since I do a lot through the woocommerce store already, I wanted to do renewals and new memberships.
I need some confirmation to see if I'm doing this correctly though - For a new membership, I think it is straight forward to simply do:
--confirm no membership entries exist already for this contact_id
$result = civicrm_api3('Membership', 'get', [ 'sequential' => 1, 'contact_id' => 15947, ]);
--Create a new membership entry
$result = civicrm_api3('Membership', 'create', [ 'membership_type_id' => "Registered Participant", 'contact_id' => 15947, 'start_date' => 20200513, 'end_date' => 20210513, 'source' => "Payment", ]);
But for a renewal, I don't want to keep adding additional lines of membership entries so I am thinking same above except if an entry is found, issue a create with the ID and it should renew it correctly?
--confirm no membership entries exist already for this contact_id
$result = civicrm_api3('Membership', 'get', [ 'sequential' => 1, 'contact_id' => 15947, ]);
-- Entry found so renew
$result = civicrm_api3('Membership', 'create', [ 'membership_type_id' => "Registered Participant", 'contact_id' => 15947, 'start_date' => 20200513, 'end_date' => 20210513, 'source' => "Payment", 'status_id' => "Current", 'id' => 8746, ]);
So the only difference between a new membership and a renewal is the 'id' and 'status_id' ?