3

I have created a custom page template and I want to display specific details of user's subscription (e.g. subscription starting date).

The available hook on 'my account' page displays this but I don't know how to dismantle the output of the hook or even merely displaying it on a page template.

Any help would be appreciated!

Sébastien
  • 11,860
  • 11
  • 58
  • 78
  • You should specify better the question,in which way you want to display the user's subscription details and why do you want to dismantle the output of the hook. After doing that maybe someone wolud try to help and answer your question. – Griseld Gerveni Sep 30 '14 at 14:59

3 Answers3

6

Add the following code in functions.php of the active theme.

add_shortcode('wdm_my_subscription', 'wmd_my_custom_function');
function wmd_my_custom_function(){
    WC_Subscriptions::get_my_subscriptions_template();
}

Now use [wdm_my_subscription] as a shortcode on the page where you want to display the User's subscription.

Screenshots:

Without Shortcode: enter image description here

Adding shortcode: enter image description here

Result:

enter image description here

If you need to modify the output of this you might need to copy the contains of get_my_subscriptions_template() function WC_Subscriptions class of the WooCommerce subscription Plugin and use it in this shortcode instead which will help you to add the details you want.

Domain
  • 11,562
  • 3
  • 23
  • 44
2

After a recent update in the Woocommerce Subscriptions plugin in WordPress

WC_Subscriptions::get_my_subscriptions_template(); is appreciated and it is replaced by new function,

so the old code needs to be updated and the following code needs to be used to create Shortcode to show users subscription

new function should be

add_shortcode('wdm_my_subscription', 'wmd_my_custom_function');
function wmd_my_custom_function(){
   WCS_Template_Loader::get_my_subscriptions();
}
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 25 '22 at 10:15
0

This last code is actually working, what i did was to just install WP snippet plugin and create a new php snippet and pasted the code and save the snippet, then activate the snippet and update it again.

Then i went to my custom page and pasted the shortcode: [wdm_my_subscription] booooom and it worked fine.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 17 '23 at 06:40