简体   繁体   中英

How to get a list of all my subscriptions in Woocommerce?

I'm trying to get a list of all my subscriptions in Woocommerce. I have read about WC_Subscriptions_Manager::get_subscription(), but I don't know how to use it. Please keep in mind that I have almost zero knowledge concerning PHP.

Someone asked a similar question on the forum. I finally used the following code:

<?php 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";
}
?>

How can I use it?

Thanks for your help!

You can use wcs_get_users_subscriptions() . If you don't pass a user_id argument, the default is to get the current user. The function returns all subscriptions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM