文档非常稀缺.我正在尝试创建一些使用woocommerce订阅(一个woocommerce插件)api的代码来获取订阅列表和每个订阅的所有细节.那里的文档和例子是如此稀缺和虚弱,我无法做到正确.以下代码不会产生任何错误,但不会输出任何订阅(只是一个空白页).如何列出所有订阅的所有详细信息?
<?PHP
if(isset($_REQUEST['Action']))
{
$Action = $_REQUEST['Action'];
switch($Action)
{
case "ValidateSubscription":
chdir("../wp-content/plugins/woocommerce-subscriptions/classes");
include '../../woocommerce/woocommerce.PHP';
//include '../woo-includes/woo-functions.PHP';
//include '../woo-includes/class-wc-dependencies.PHP';
include 'class-wc-subscriptions-manager.PHP';
$Subscriptions = WC_Subscriptions_Manager::get_all_users_subscriptions();
print_r($Subscriptions);
break;
default:
echo "invalid action";
}
}else
{
echo "no action specified";
}
解决方法:
这不是你在外部代码中包含wordpress功能的方式.试试这个.
if(isset($_REQUEST['Action']))
{
$Action = $_REQUEST['Action'];
switch($Action)
{
case "ValidateSubscription":
include('../wp-load.PHP'); //Guessing this path based on your code sample... should be wp root
$Subscriptions = WC_Subscriptions_Manager::get_all_users_subscriptions();
print_r($Subscriptions);
break;
default:
echo "invalid action";
}
}else
{
echo "no action specified";
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。