I am using paid memberships pro plugin to manage memberships on a news site under development with a custom registration page that leads to a custom pricing (levels) page upon successful signup which uses the paystack inline js library instead of the payment gateway to handle payments and upon successful payment, the MemberOrder Class is used to generate the order and also update the user membership level.
The problem being faced now is, if a user subscribes to a membership plan with a 30 days duration, upon checking the Orders section of the paid memberships pro settings, the Registration and Start Date are assigned successfully and accurately, but the End Date is set to "Never" instead of a date 30 days from the Start Date. How can this be corrected as I have gone through the entire paid memberships pro documentation unsuccessfully.
The Order End Date to be set to the date 30 days from the Start Date and not "Never".
// Update the membership level for the user
pmpro_changeMembershipLevel(substr($decrypted_data, 19, 1), $user_id); // Change membership level
if (!$order->payment_transaction_id) {
// Query to check if order_id/payment_transaction_id already exists in database, in the event someone is trying to reuse a successful payment ID
$order->code = $order_id;
$order->user_id = $user_id;
$order->payment_transaction_id = $order_id;
$order->total = $membership_amount;
$order->membership_id = substr($decrypted_data, 19, 1);
$order->gateway = 'PayStack';
$order->status = 'success';
// Save object
$order->saveOrder();
}
2
Answers
@Noel Bürgler Thanks for your answer but it can't work as the MemberOrder class does not have an enddate property. However, I was able to solve this problem after a bit of fiddling and I decided to share the answer here as I have noticed quite a lot of people facing same problem and not wanting to pay for PMPRO support just for that.
Below is how the problem was solved by me:
Hope this helps someone else going through the same issue as I was :)
Try this:
It retrieves the membership level details using pmpro_getLevel($level_id) and then calculates the End Date based on the expiration number and period.