• Resolved Colin

    (@colinsafranek)


    Hi, thanks for the wonderful work on WC!

    Before 2.6 I was able to build my own “tabbed” My Account page by using remove_action to remove hooked sections, and then by using wc_get_template() to insert all the my account template parts into my “tab” containers.

    After the update to 2.6 I am finding that the current user and/or user id is not getting passed to the WC template parts. For example when I use wc_get_template( 'myaccount/orders.php' ); in my custom myaccount.php template file, no orders display for users who I know have past orders.

    Also for the myaccount/form-edit-account.php template part, the user’s name and email were not populating their respective fields. So I tried the following:

    $user = wp_get_current_user();
    
    wc_get_template(
        'myaccount/form-edit-account.php',
        array(
            'user' => $user,
        )
    );

    The above worked for the form-edit-account.php, successfully populating the fields with the current user’s info, but did not solve the issue with the orders.php template, which was still blank.

    It seems like perhaps each template part requires a different set of parameters to be passed, in order to render properly, but I can’t seem to figure out which template part requires which parameters. Is there documentation on that?

    I would like to continue using my own tabs because no page reload is required to access each tab’s content. But I would like my template to be totally compliant with the latest WC customization standards. So if you think I could accomplish my goal in a better way, I am open to suggestions.

    I hope I have communicated my problem well. Please let me know.

    Basically I would like to be able to manually insert any and all myaccount template parts into specific locations in my custom template, making sure that all template parts render correctly with the current user’s information.

    Thanks in advance for your help!

    https://www.ads-software.com/plugins/woocommerce/

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Contributor Claudio Sanches

    (@claudiosanches)

    Better use your tabbed My Account now, since it will provide more support for plugins and themes (because our new filters, actions and endpoints).
    Here you can find docs about of how customize the tabbed My Account page: https://github.com/woothemes/woocommerce/wiki/2.6-Tabbed-My-Accout-page

    Thread Starter Colin

    (@colinsafranek)

    Yes, I have already read that wiki, but it doesn’t give any information about how to render the endpoint content without using the endpoint system.

    I would like to organize the myaccount page differently, and avoid having to reload the page for each section. Is there any documentation on that?

    Is wc_get_template() a good method? Is there a better method?

    In the 2.6 release announcement, they said the new tabbed my-account template was created to reduce load time for sites with many WC extensions, but if you only have a few WC extensions and the my account page loads fast already, this new tabbed system is actually slower than the old system, because the user has to wait for the page to load every time they switch between tabs. That’s not an improvement in my opinion.

    Could you make any suggestions re: my original question?

    It would be much appreciated.

    Thread Starter Colin

    (@colinsafranek)

    I just need to know which parameters to pass to which my account template parts so that they render with the current user’s information (i.e. user object or user id). Can you help me with that?

    Plugin Contributor Claudio Sanches

    (@claudiosanches)

    I would like to organize the myaccount page differently, and avoid having to reload the page for each section. Is there any documentation on that?

    Nop and you really should use the new endpoints.

    this new tabbed system is actually slower than the old system, because the user has to wait for the page to load every time they switch between tabs

    Not true, since we don’t load all the data at the same time as before.
    And not any importance to load the page to access a new page.

    Good luck!

    Plugin Contributor Claudio Sanches

    (@claudiosanches)

    Don’t forget that plugins will soon start adding new menus too, such as WooCommerce Subscriptions, then it will be increasingly difficult to maintain what you did working.

    Plugin Contributor Claudio Sanches

    (@claudiosanches)

    I just need to know which parameters to pass to which my account template parts so that they render with the current user’s information (i.e. user object or user id). Can you help me with that?

    No idea, since I have no idea how you did your customization.

    Thread Starter Colin

    (@colinsafranek)

    That’s very disappointing ?? I was hoping you could at least point me in the right direction.

    Not true, since we don’t load all the data at the same time as before.

    Actually it is definitely true!

    Scenario 1: load everything on the my account page at once – load time = 1 second

    Scenario 2: load each section separately – load time = .5 seconds

    If you have 5 sections on your my account page, scenario 2 will require 2.5 seconds of browser load time to view them all, versus 1 second in scenario 1.

    Am I missing something?

    Anyway, the best thing about WooCommerce is it customizability. If I switch to the new tabbed my account endpoints, I will be drastically changing my customers’ user experience, for the worse. It sucks that you aren’t at least telling me that what I want to do is possible, especially since it was possible in the previous version. I only want to continue doing what I’m currently doing, but you’re telling me that it isn’t possible?

    C’mon man. Help me out.

    Plugin Contributor Claudio Sanches

    (@claudiosanches)

    That’s very disappointing ?? I was hoping you could at least point me in the right direction.

    Sorry, but how? No idea what you did or is doing.

    Am I missing something?

    Yes! My Account pages carrying massive data without any cache on a page that can not be cached. “load time = 1 second”? Lucky man you are!
    In several cases had pages with much more than 60 seconds and even bursting the PHP memory limit and now we can split it into little subpages, no more problems with long queries or PHP memory limit.
    This is the scenario of multiple of our users.

    I understand your point of view, so I wish you good luck with your custom code.

    especially since it was possible in the previous version. I only want to continue doing what I’m currently doing

    And you don’t need to use the new tabbed My Account page, you can keep your old templates, no problem.

    Thread Starter Colin

    (@colinsafranek)

    Ok, I’m sorry, I guess I wasn’t clear in my original question.

    Let’s just take one example:

    Before the 2.6 update I used the following to display the “My Orders” section:

    wc_get_template( 'myaccount/my-orders.php', array( 'order_count' => $order_count ) );

    But now that the my-orders.php template is deprecated, I would like to use the orders.php template instead. But when I use the same function with the new orders.php template part, no orders are displayed. Instead it says “No order has been made yet.”

    I tried the following:

    wc_get_template(
        'myaccount/orders.php',
        array(
            'order_count' => $order_count,
            'user'        => $user,
        )
    );

    But I can’t get the orders to display.

    So what parameters do I need to pass to the above function to get it working again?

    Plugin Contributor Claudio Sanches

    (@claudiosanches)

    But now that the my-orders.php template is deprecated, I would like to use the orders.php template instead

    Not really, you can keep using the my-orders.php template, at least until WooCommerce 3.0.

    But when I use the same function with the new orders.php template part, no orders are displayed. Instead it says “No order has been made yet.”

    No need to use wc_get_template(), it’s better if you use the woocommerce_account_orders( 1 ) function.
    You can find this function and others in: https://plugins.svn.www.ads-software.com/woocommerce/tags/2.6.0/includes/wc-template-functions.php

    Here the source code of woocommerce_account_orders():

    	/**
    	 * My Account > Orders template.
    	 *
    	 * @param int $current_page Current page number.
    	 */
    	function woocommerce_account_orders( $current_page ) {
    		$current_page    = empty( $current_page ) ? 1 : absint( $current_page );
    		$customer_orders = wc_get_orders( apply_filters( 'woocommerce_my_account_my_orders_query', array( 'customer' => get_current_user_id(), 'page' => $current_page, 'paginate' => true ) ) );
    
    		wc_get_template(
    			'myaccount/orders.php',
    			array(
    				'current_page' => absint( $current_page ),
    				'customer_orders' => $customer_orders,
    				'has_orders' => 0 < $customer_orders->total,
    			)
    		);
    	}
    

    And yes, all tabbed My Account endpoints have functions like that ??

    Thread Starter Colin

    (@colinsafranek)

    Thank you!

    Thread Starter Colin

    (@colinsafranek)

    resolved-ish

    No need to use wc_get_template(), it’s better if you use the woocommerce_account_orders( 1 ) function.
    You can find this function and others in: https://plugins.svn.www.ads-software.com/woocommerce/tags/2.6.0/includes/wc-template-functions.php

    I am having the same issue whilst trying to create a custom my-account page. I want to be able to display the users personal details (first name, last name etc) and billing/shipping addresses. When I follow your method I cannot get any content to display. Can you explain howto implement the woocommerce_account_orders function.

    P.s. I am new to coding and Woocommerce

    Thanks

    Thread Starter Colin

    (@colinsafranek)

    Hey @cnomadl, I ended up going an entirely different direction and using the plugin: “SS WooCommerce Myaccount Ajax Tabs” (find it on code canyon here: https://codecanyon.net/item/ss-woocommerce-myaccount-ajax-tabs/16948806).

    It works quite nicely and is customizable to my needs. You can still hook into the my account tabs in the woocommerce recommended way and the plugin accommodates those customizations.

    Good luck!

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Using wc_get_template for custom my account page after 2.6 update.’ is closed to new replies.