首页 > 解决方案 > 如何修复 class-wp-meta-query 中的“trim() 需要参数 1”-> 要选择哪个 Meta Key?

问题描述

我正在开发一个外部应用程序,该应用程序通过我的网站(使用 woocommerce)使用来自注册用户的数据来登录应用程序。

我想误用产品到期(您可以在 woocommerce 中创建的产品的产品属性)来检查该人是否仍然可以下载产品并因此也可以登录,或者如果不能,客户应该无法登录。

我在 php 方面并没有真正的经验,并且阅读了 wc 的文档,但这对我没有帮助。

我通过登录从客户那里获得凭据,然后我想使用这些数据来获取订单。从订单中我想看看我是否可以得到产品,然后检查产​​品到期是否仍然有效。

元键会产生一些问题,因为我将它与一个对象配对。错误信息是:

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"));
                    }
                }
            }
        }
    }

?>

有什么想法我可以更改才能登录吗?

标签: phpwordpressdebuggingwoocommercecustomer

解决方案


推荐阅读