How can I use the $subscriptions variable outside of the my-subscriptions.php template?

47 Views Asked by At

I am using Woocommerce Subscription extension, and I would like to display the current subscription orders located in the my-subscriptions.php template on the orders.php template (normal woocommerce template).

When I copy the code over, I get the message of "Undefined variable: subscriptions".

How do I get round this?

EDIT: My files are as follows :

Orders.php - https://pastebin.com/0fxgAjyp
my-subscriptions.php - https://pastebin.com/XhbWEBSp
1

There are 1 best solutions below

2
Arshid KV On

I think you are accessing the variable inside the function. Please try with global

my-subscriptions.php

function custom_func(){
  global $subscriptions;
}

orders.php

include `my-subscriptions.php`;
 global $subscriptions;
echo   $subscriptions;