skip to Main Content

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


  1. Chosen as BEST ANSWER

    @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:

    // First, establish a database connection
    $servername = "localhost";
    $username = "username";
    $password = "password";
    $dbname = "database_name";
    
    $conn = new mysqli($servername, $username, $password, $dbname)
    
    $plan_id = 1; //set your plan id
    
    $expiration_date = date('Y-m-d', strtotime('+30 days')); //set your enddate
    
    pmpro_changeMembershipLevel($plan_id, $user_id); //update user membership level
    
    $order = new MemberOrder();
    
    $order->code = $decoded_data->data->id;
    $order->user_id = $user_id;
    $order->payment_transaction_id = $decoded_data->data->reference;
    $order->total = $decoded_data->data->amount / 100;
    $order->membership_id = $plan_id;
    $order->gateway = 'PayStack';
    $order->status = 'success';
    
    // Save object
    $order->saveOrder(); //save order
    
    // Next, define the update query to update enddate
    $sql = "UPDATE wp_pmpro_memberships_users SET enddate = '$expiration_date' WHERE user_id = '$user_id'";
    
    // Execute the enddate update query
    $conn->query($sql);
    
    // close the database connection
    $conn->close();
    

    Hope this helps someone else going through the same issue as I was :)


  2. Try this:

    // Update the membership level for the user
    $level_id = substr($decrypted_data, 19, 1);
    pmpro_changeMembershipLevel($level_id, $user_id); // Change membership level
    
    // Get the level details to calculate the End Date
    $level = pmpro_getLevel($level_id);
    if ($level->expiration_number > 0) {
        $end_date = date('Y-m-d', strtotime("+{$level->expiration_number} {$level->expiration_period}", current_time('timestamp')));
    } else {
        $end_date = '0000-00-00 00:00:00';
    }
    
    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 = $level_id;
        $order->gateway = 'PayStack';
        $order->status = 'success';
        $order->enddate = $end_date; // Set the End Date for the order
        // Save object
        $order->saveOrder();
    }
    

    It retrieves the membership level details using pmpro_getLevel($level_id) and then calculates the End Date based on the expiration number and period.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search