I'm using WooCommerce v3.2.6 and WordPress 4.9.1.
I've added an endpoint to the WooCommerce myaccount area (view-subscription
):
function my_custom_endpoints() {
add_rewrite_endpoint( 'view-subscription', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'my_custom_endpoints' );
function my_custom_query_vars( $vars ) {
$vars[] = 'view-subscription';
return $vars;
}
add_filter( 'query_vars', 'my_custom_query_vars', 0 );
function view_subscription_endpoint_content() {
include get_template_directory().'/woocommerce/myaccount/view-subscription.php';
}
add_action( 'woocommerce_account_view-subscription_endpoint', 'view_subscription_endpoint_content' );
The endpoint is working but I want to be able to pass the ID of a subscription (a post type) to the endpoint (similar to how view-order works). How can I do this?
eg.
myaccount/view-order/21313 - Displays details of order #21313
myaccount/view-subscription/35464 - I want this to display the details of the subscription post #35464.
If I go to the above URL myaccount/view-subscription/35464
, the view-subscription.php template is still loading, but what is the best way to access the ID, 35464, from the URL?
I'm using WooCommerce v3.2.6 and WordPress 4.9.1.
I've added an endpoint to the WooCommerce myaccount area (view-subscription
):
function my_custom_endpoints() {
add_rewrite_endpoint( 'view-subscription', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'my_custom_endpoints' );
function my_custom_query_vars( $vars ) {
$vars[] = 'view-subscription';
return $vars;
}
add_filter( 'query_vars', 'my_custom_query_vars', 0 );
function view_subscription_endpoint_content() {
include get_template_directory().'/woocommerce/myaccount/view-subscription.php';
}
add_action( 'woocommerce_account_view-subscription_endpoint', 'view_subscription_endpoint_content' );
The endpoint is working but I want to be able to pass the ID of a subscription (a post type) to the endpoint (similar to how view-order works). How can I do this?
eg.
myaccount/view-order/21313 - Displays details of order #21313
myaccount/view-subscription/35464 - I want this to display the details of the subscription post #35464.
If I go to the above URL myaccount/view-subscription/35464
, the view-subscription.php template is still loading, but what is the best way to access the ID, 35464, from the URL?
2 Answers
Reset to default 2I hope it's not too late, but anyway, I know it will help someone else.
echo get_query_var('your-endpoint');
So, for your code, it will be:
echo get_query_var('view-subscription');
Please use this, it will help me according same as view-order link.
wc_get_endpoint_url()
eg.
myaccount/view-order/21313
- Displays details of order #21313
myaccount/view-coupon/123
- Display details of coupon #123