wordpress 付费会员资格专业会员资格订单结束日期设置为从不

u5i3ibmn  于 2023-04-11  发布在  WordPress
关注(0)|答案(2)|浏览(198)

我使用付费会员亲插件管理会员在一个新闻网站正在开发的自定义注册页面,导致一个自定义定价(水平)页面成功注册后,使用paystack内联js库,而不是支付网关来处理付款和成功支付,MemberOrder类用于生成订单,也更新用户的会员资格级别.
现在面临的问题是,如果用户订阅了为期30天的会员计划,在检查付费会员专业设置的订单部分时,注册和开始日期被成功且准确地分配,但结束日期被设置为“从不”,而不是从开始日期起30天的日期。如何才能纠正这一点,因为我已经通过了整个支付会员亲文件不成功。
订单结束日期应设置为自开始日期起30天的日期,而不是“从不”。

// 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();
        }
wfsdck30

wfsdck301#

试试这个:

// 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();
}

它使用pmpro_getLevel($level_id)检索成员资格级别详细信息,然后根据到期号和期限计算EndDate。

8zzbczxx

8zzbczxx2#

@诺埃尔Bürgler感谢您的回答,但它不能工作,因为MemberOrder类没有enddate属性。然而,经过一番折腾,我能够解决这个问题,我决定在这里分享答案,因为我注意到很多人面临同样的问题,不想为此支付PMPRO支持。
下面是我如何解决这个问题的:

// 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();

希望这能帮助其他和我一样经历同样问题的人:)

相关问题