I am adding successfully a new custom tab to WooCommerce My account section. But I'm not able to change the menu item link, it stays tied to the 'my-account' URL.
I want to remove the http://site-test.local/my-account
from this absolute link "http://site-test.local/my-account/https:/mycustomwebsite.com/"
I just want to have "https:/mycustomwebsite.com/" when I do click on the "NEW CUSTOM TAB" menu link.
Here is the code I added to my theme functions.php file:
function custom_add_my_account_menu_item($items) {
// Add a new menu item with the key 'custom_option'
$items['https://mycustomwebsite.com'] = __('NEW CUSTOM TAB', 'your-text-domain');
$cleanLink = str_replace('http://site-test.local/my-account', '', $items); //I'm trying to remove the site-test.local/my-account, but it doesn't work
$items = $cleanLink;
return $items;
}
add_filter('woocommerce_account_menu_items', 'custom_add_my_account_menu_item');
// Display content for the custom option in the My Account section
function custom_my_account_endpoint_content() {
echo '<p>This is the content for the custom option.</p>';
}
add_action('woocommerce_account_custom_option_endpoint', 'custom_my_account_endpoint_content');
How to change the menu item link to a custom link?
To set a custom link to a custom My Account menu item, you can use the following instead:
Code goes in functions.php file of your child theme (or in a plugin). Tested and works.
If you want to open the link in a new window, replace the last function with:
Note that with a custom menu item link, the related tab content will never get displayed.