Woocommerce My Account Endpoint – how to get ID parameter from URL?
Question
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?
0
endpoints, woocommerce
6 years
2018-01-24T07:12:04-05:00
2018-01-24T07:12:04-05:00 0 Answers
76 views
0
Leave an answer