How to display user's WooCommerce subscription details?

对着背影说爱祢 提交于 2021-02-08 03:32:26

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/26111508/how-to-display-users-woocommerce-subscription-details

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!