将 woocommerce 默认页面设置为订单而不是新仪表板

问题描述 投票:0回答:1

在 woocommerce 4.0 更新后,新的管理仪表板将添加到 woocommerce 菜单项中,并成为主菜单项,当您从管理面板中单击 woocommerce 时,它会将您重定向到新的仪表板页面,而不是像以前一样的订单页面,我们仍然使用仪表板,我们不需要完全禁用它。

但是我们希望 woocommerce 菜单项在单击时像 4.0 更新之前一样转到订单页面,而不是新的仪表板项目。

php wordpress woocommerce
1个回答
0
投票

不太优雅。但我是这样解决问题的。

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;
}
© www.soinside.com 2019 - 2024. All rights reserved.