0

I'm working on a custom Woocommerce theme. I've already figured out how to add the Wishlist label to the Woocommerce my account navigation. When you click on the Wishlist navigation item, you go to domain.com/my-account/wishlist. But it the "view" doesn't exist yet.

/*
* Register new wishlist endpoint
*/
function add_wishlist_endpoint() {
    add_rewrite_endpoint( 'wishlist', EP_ROOT | EP_PAGES );
}

add_action( 'init', 'add_wishlist_endpoint' );


/*
* Register new wishlist endpoint
*/
function wishlist_query_vars( $vars ) {
    $vars[] = 'wishlist';
    return $vars;
}

add_filter( 'query_vars', 'wishlist_query_vars', 0 );

So I've created a new file my-wishlist.php in my theme in the Woocommerce folder (themes/my-theme/woocommerce/myaccount/my-wishlist.php)

<?php
    if ( ! defined( 'ABSPATH' ) ) {
        exit;
    }

    echo do_shortcode('[yith_wcwl_wishlist]');
?>

I want that the my-wishlist.php file is shown on the right side of the navigation like the orders, addresses, account details. So when you click on the Wishlist menu item, you still see the account navigation on the left side.

Screenshot my account

My account page template looks like this:

<sidebar>
<?php 
    do_action( 'woocommerce_account_navigation' );
?>
</sidebar>

<main>
<?php
    do_action( 'woocommerce_account_content' );
?>
</main>
3
  • Does this answer your question? Jul 30, 2020 at 9:20
  • It doesn't give a 404 anymore. But where do I say that woocommerce has to use this file: themes/my-theme/woocommerce/myaccount/my-wishlist.php ?
    – Dennis
    Jul 30, 2020 at 9:28
  • 1
    You need to hook into woocommerce_account_wishlist_endpoint and include the template from there. Jul 30, 2020 at 9:51

1 Answer 1

0
 add_action('woocommerce_account_wishlist_endpoint', function() {
    $wishlists = [];

    wc_get_template('myaccount/my-wishlist.php', [
        'wishlists' => $wishlists
    ]);
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.