我正在使用一个外部应用程序,该应用程序通过我的网站(使用woocommerce)使用注册用户的数据登录该应用程序。
我想滥用产品有效期限(您可以在woocommerce中创建的产品的产品属性)来检查该人员是否仍然可以下载该产品并因此也可以登录,否则客户应该无法登录。
我对php没有真正的经验,也没有阅读过wc的文档,但这对我没有帮助。
我通过登录名从客户那里获得凭证,然后我想使用数据来获取订单。我要从订单中查看是否可以获取产品,然后检查产品有效期是否仍然有效。
由于我将meta键与一个对象配对,因此meta键会引起一些问题。错误消息是:
PHP Warning: trim() expects parameter 1 to be string, object given in
../wp-includes/class-wp-meta-query.php on line 599.
但是,如果我使用_customer_user
(在某些解决方案中看到的话),则对我不起作用:
<?php
/*
Template Name: Login
*/
?>
<?php
require_once('./wp-includes/pluggable.php');
$sEmail = $_POST['email'];
$sPassword = $_POST['password'];
$sSecret = $_POST['secret'];
$oUser = get_user_by('email', $sEmail);
$iUserID = $oUser->ID;
$sUserName = $oUser->user_login;
if(!isset($sEmail) || !isset($sPassword) || !isset($sSecret)) {
die();
}
$local_secret = 'XXXXXXXXXXXX';
// Get the last order by email, orderd by the most recent order and
//$args = array(
//'customer' => $sEmail,
//'orderby' => 'date',
//'order' => 'DESC',
//);
//$oLastOrder = wc_get_order( $args );
// Get orders by customer with email 'woocommerce@woocommerce.com'.
// Get all current customer orders
$customer_orders = wc_get_orders( $args = array(
'numberposts' => -1,
'meta_key' => $oUser,
'meta_value' => $iUserID,// for current user id
'post_status' => array_keys(wc_get_order_statuses()),
) );
// The different loops to get the downloadable products bought by this user
foreach ( $customer_orders as $customer_order )
if (!empty($customer_orders)){
foreach ( $customer_orders as $customer_order ){
if( !$customer_order->has_downloadable_item() && $customer_order->is_paid() ){
foreach( $customer_order->get_items() as $item ){
$item_id = $item[614]; // product ID
// Just the downloadable items Below
if($item->is_download_permitted()) {
//Check Credentials
if ($sSecret == $local_secret) {
if ($user && wp_check_password( $password, $user->data->user_pass, $user->ID )) {
echo json_encode(array("success" => "true"));
}else {
echo json_encode(array("success" => "false"));
}
}else {
echo json_encode(array("success" => "false"));
}
//End of Credentialscheck
} else {
echo json_encode(array("success" => "false"));
}
}
}
}
}
?>
有什么想法可以更改以能够登录吗?