移除 WooCommerce 个人中心的下载功能

如果你希望 移除 WooCommerce 个人中心(用户账户页面)中的下载部分,即 下载链接 或 “我的下载” 部分,可以通过以下方法来实现。这里的操作主要是通过添加一些代码来隐藏或移除下载相关的功能。

使用自定义代码隐藏下载选项

将以下代码添加到您的当前启用主题functions.php 文件中

// 移除 WooCommerce 个人中心中的下载链接
function remove_woocommerce_downloads_tab( $tabs ) {
    if ( isset( $tabs['downloads'] ) ) {
        unset( $tabs['downloads'] ); // 移除下载标签
    }
    return $tabs;
}
add_filter( 'woocommerce_account_menu_items', 'remove_woocommerce_downloads_tab' );

// 移除下载页面内容
function remove_downloads_page_content() {
    if ( is_account_page() && isset( $_GET['downloads'] ) ) {
        wp_redirect( get_permalink( wc_get_page_id( 'myaccount' ) ) ); // 重定向回账户页面
        exit;
    }
}
add_action( 'template_redirect', 'remove_downloads_page_content' );

解释:

移除下载标签:remove_woocommerce_downloads_tab 函数会从 WooCommerce 账户菜单中移除 “下载” 标签。

重定向下载页面:如果用户访问 我的账户 > 下载 页面,remove_downloads_page_content 函数会将他们重定向回 我的账户 页面,避免显示下载内容。