Maged Mohamed
Maged Mohamed

Reputation: 561

Set woocommerce default page to orders instead of new dashboard

Simply after the update of woocommerce 4.0 a new admin dashboard is added to the woocommerce menu items and become the main menu item when you click on woocommerce from the admin panel it redirects you to the new dashboard page instead of orders page as before, we still use the dashboard we don't need to disable it completely.

But we want the woocommerce menu item when its clicked to go to the orders page as before the 4.0 update not the new dashboard item.

Upvotes: 1

Views: 119

Answers (1)

EndyVelvet
EndyVelvet

Reputation: 441

Not exactly elegant. But I solved the problem this way.

add_action('template_redirect', 'redirect_my_account_orders', 1);

function redirect_my_account_orders() {
    // List of all possible WooCommerce endpoints to check
    $excluded_endpoints = array('orders', 'edit-account', 'edit-address', 'payment-methods', 'downloads', 'customer-logout', 'subscriptions', 'subscription', 'add-payment-method');

    // Check if the current URL matches any of the excluded endpoints
    foreach ($excluded_endpoints as $endpoint) {
        if (is_wc_endpoint_url($endpoint)) {
            return;
        }
    }

    // If we're on the "My Account" page and not on any endpoint, redirect to "Orders"
    if (is_account_page() && !is_wc_endpoint_url()) {
        wp_safe_redirect(wc_get_endpoint_url('orders', '', wc_get_page_permalink('myaccount')));
        exit;
    }
}

add_filter('woocommerce_account_menu_items', 'remove_my_account_dashboard' );

function remove_my_account_dashboard($items) {
    unset($items['dashboard']);
    return $items;
}

Upvotes: 0

Related Questions