0

I would like to add a link in the My Account -> Orders -> Order Details page, that would point to a custom view-photo.php file, which will display a few images of the product from that order. I've placed that file in custom-theme/woocommerce/myaccount.

I've added this to theme's function.php file:

add_action( 'init', 'add_endpoint' );
function add_endpoint(){
    add_rewrite_endpoint( 'photos', EP_ROOT | EP_PAGES );
}

add_filter( 'wc_get_template', 'custom_endpoint', 10, 5 );
function custom_endpoint($located, $template_name, $args, $template_path, $default_path){

    if( $template_name == 'myaccount/view-photos.php' ){
        global $wp_query;
        if(isset($wp_query->query['view-photos'])){
            $located = get_stylesheet_directory() . '/woocommerce/myaccount/view-photos.php';
        }
    }

    return $located;
}

I've tried linking to view-photos.php from Order Details page in multiple ways, by setting href to 'view-photos', 'view-photos.php', '../view-photos', and such, but I cannot get to view-photos.php in any way.

Currently, in My Account -> Orders page, link to Order details page goes something like this: .../my-account/view-order/#order-no. I would like for this link to view-photos.php to be similar: .../my-account/view-photos/#order-no.

How do I link to that page? And how to link back to Orders Details page from that page?

  • 1
    You need to flush WordPress rewrite rules… you should go in WordPress Settings > Permalinks and click on "save" … – LoicTheAztec Apr 15 '17 at 18:16
  • Done that, but still nothing. I'm not sure how to link to view-photos.php from Order details page. But even when I manually enter the link ... /my-account/view-photos/{order-#}/, I get Page not found error. I've found this as an href value in the orders.php that links to Order details page: `get_view_order_url() ); ?>` Маybe I need to have something like that, e.g. `$order->get_view_photos_url()`, but how to create that and make it point to my own view-photos.php? –  Apr 17 '17 at 11:03
  • Have you looked at this thread: http://stackoverflow.com/questions/38039616/woocommerce-assigning-an-endpoint-to-a-custom-template-in-my-account-pages/38056768#38056768 or at this official documentation: https://woocommerce.wordpress.com/2016/04/21/tabbed-my-account-pages-in-2-6/ – LoicTheAztec Apr 17 '17 at 11:18
  • I was just reading that and tried that solution. I don't want the link to view-photos to appear in the tabs on the left, I just need a link from Order details page. After trying this solution, when I manually enter the link in the address bar(.../my-account/view-photos/{order-no}/, I don't get Page not found error any more, but it doesn't load the right page yet, it loads My account page instead. –  Apr 17 '17 at 11:23

0 Answers0