MomasVII
MomasVII

Reputation: 5061

Use theme when creating a new WOocommerce Account page

I have created a new menu item to my my-account page in Woocommerce and I am wondering how I can create a theme file for it so I can add in some custom code to display orders and other backend stuff. Here is how I added the menu item

I duplicated the woocommerce/myaccount folder in my theme and added a 'your-approvals' page but can't get it to use that page.

add_action( 'init', 'metrodiamonds_add_endpoint' );
function metrodiamonds_add_endpoint() {

    // WP_Rewrite is my Achilles' heel, so please do not ask me for detailed explanation
    add_rewrite_endpoint( 'your-approvals', EP_PAGES );
}

How can I assign my themes/mytheme/woocmmerce/myaccount/your-approvals to the new menu item I created?

Thanks

Upvotes: 2

Views: 158

Answers (1)

ZecKa
ZecKa

Reputation: 2934

Because add_rewrite_endpoint only create the endpoint, but doesn't configure the display function for this endpoint.

You have to use woocommerce_account_<key>_endpoint action. And then, call the desired template part with wc_get_template_part

add_action( 'woocommerce_account_your-approvals_endpoint', 'metrodiamonds_your_approvals_endpoint_content' );
function metrodiamonds_your_approvals_endpoint_content() {
    wc_get_template_part("myaccount/your-approvals");
}

After define the your endpoint with add_rewrite_endpoint, be sure to Save Permalinks ( In the WordPress admin area, go to “Settings > Permalinks” the "Save Changes")

After that, you probably want to add your new account page to my account menu

You can do as follow:

function metrodiamonds_add_your_approvals_menu__my_account( $items ) {
    $items['your-approvals'] = 'Your Approvals';
    return $items;
}
  
add_filter( 'woocommerce_account_menu_items', 'metrodiamonds_add_your_approvals_menu__my_account' );

Upvotes: 2

Related Questions