Skip to content

Instantly share code, notes, and snippets.

@azinkey
Created February 9, 2022 13:23
Show Gist options
  • Save azinkey/7ef5f626b13ca84ab26c9998a5b844e8 to your computer and use it in GitHub Desktop.
Save azinkey/7ef5f626b13ca84ab26c9998a5b844e8 to your computer and use it in GitHub Desktop.
<?php
add_action( 'init', 'add_videos_endpoint' );
function add_videos_endpoint(){
add_rewrite_endpoint( 'videos', EP_ROOT | EP_PAGES );
}
function az_videos_query_vars( $vars ) {
$vars[] = 'videos';
return $vars;
}
add_filter( 'query_vars', 'az_videos_query_vars', 0 );
function az_videos_flush_rewrite_rules() {
flush_rewrite_rules();
}
add_action( 'wp_loaded', 'az_videos_flush_rewrite_rules' );
add_filter ( 'woocommerce_account_menu_items', 'az_account_menu_videos' );
function az_account_menu_videos( $menu_links ){
$new = array( 'videos' => '30 Day Challenge' );
$menu_links = array_slice( $menu_links, 0, 1, true ) + $new + array_slice( $menu_links, 1, NULL, true );
return $menu_links;
}
add_filter( 'wc_get_template', 'az_videos_endpoint', 10, 5 );
function az_videos_endpoint($located, $template_name, $args, $template_path, $default_path){
if( $template_name == 'myaccount/my-videos.php' ){
global $wp_query;
if(isset($wp_query->query['videos'])){
$located = get_stylesheet_directory() . '/woocommerce/myaccount/my-videos.php';
}
}
return $located;
}
add_action( 'woocommerce_account_videos_endpoint', 'az_account_menu_videos_endpoint' );
function az_account_menu_videos_endpoint() {
wc_get_template(
'myaccount/my-videos.php',
array(
'current_user' => get_user_by( 'id', get_current_user_id() ),
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment