I want to add a custom endpoint url to my-account page on woocommerce. is it possible? So when customer clicks to this link they will redirect to my youtube page
function custom_wc_end_point() {
if(class_exists('WooCommerce')){
add_rewrite_endpoint( 'videos', EP_ROOT | EP_PAGES );
}
}
add_action( 'init', 'custom_wc_end_point' );
function custom_endpoint_query_vars( $vars ) {
$vars[] = 'videos';
return $vars;
}
add_filter( 'query_vars', 'custom_endpoint_query_vars', 0 );
function ac_custom_flush_rewrite_rules() {
flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'ac_custom_flush_rewrite_rules' );
// add the custom endpoint in the my account nav items
function custom_endpoint_acct_menu_item( $items ) {
$download = $items['downloads'];
unset( $items['downloads'] );
$items['videos'] = __( 'Watch Videos ', 'woocommerce' ); // replace videos with your endpoint name
$items['downloads'] = $download;
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'custom_endpoint_acct_menu_item' );
function youtube_custom_endpoint() {
// Is it possible wehn click on this link it move to my youtube page
}
add_action( 'woocommerce_account_videos_endpoint', 'youtube_custom_endpoint' );
I know this question has been around for a while but i'd like to write my answer to help someone either now or in future. Was working on a Digital eCommerce project that requires heavy customization to match EDD. This question is one of the customization (in which i don't want the edit-address endpoint to be accessible; instead it should redirect to edit-account endpoint. I as well tested this code to answer your question and was redirected to YouTube. Customize to suit your need.
Code goes in function.php file of your active child theme (or active theme). Tested and works.
just change the "Candidate Dashboard" which is the the page name or the title name that appear in the my-account menu.
second thing change the URL to your url, i make it in bold the things to be changed.
Best,
You can use the "woocommerce_get_endpoint_url" filter to achieve what you want: