P粉7258276862023-08-28 21:32:12
You can achieve this in the following two ways:
Place null value in background settings
Go to WooCommerce > Settings > Advanced and in the Account endpoint input box you can delete the value for the specific endpoint and save the empty value.
This way you won't see the endpoint page or menu item on the account page, if you visit that URL you will see the homepage on the URL you visit.
Unset query variables
You can use filter hooks to unset query variables.
https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/includes/class-wc-query.php#L85
At line 85
you can find the function with all query variables.
https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/includes/class-wc-query.php#L232
And on line 232 you can find the function that gets the query variables, which also has filters. You can use a filter and unset the required endpoints.
If you use this method, you will also need to unset the item from the navigation menu item, and you will also need to resave the permalink settings.
Then, if you visit the URL of that endpoint, you will see the home page at the URL you visit.
In both cases, you will not see a 404 page.
P粉2176290092023-08-28 15:42:08
The answer is: Yes, there is! My hook was written wrong. I now use wp hooks. Is this legal?
function redirect_forbidden_access(){ $current_endpoint = WC()->query->get_current_endpoint(); if($current_endpoint == "payment-methods" || $current_endpoint == "add-payment-method" || $current_endpoint == "edit-payment-method" || $current_endpoint == "[custom-endpoint]") { wp_redirect(wc_get_account_endpoint_url('dashboard')); } } add_action('wp', 'redirect_forbidden_access');
This is the solution.