如何隱藏或顯示所有 WooCommerce 管理、選單、子選單、小工具

這篇文章所提供的是所有 WooCommerce 的菜單、子菜單、元框和桌面小部件設定 code,您可以從每個代碼中選擇要使用或是不使用功能,這完全由你決定。

這篇文章所提供的是所有 WooCommerce 的菜單、子菜單、元框和桌面小部件設定 code,您可以從每個代碼中選擇要使用或是不使用功能,這完全由你決定。

如何隱藏 Woocommerce 選單

/** Hide Woocommerce menus and submenus **/
function hostfree_hide_woo_menus() {
	//Hide "Marketing".
	remove_menu_page('wc-admin&path=/marketing');
	//Hide "Tools → Scheduled actions".
	remove_submenu_page('tools.php', 'action-scheduler');
	//Hide "WooCommerce".
	remove_menu_page('woocommerce');
	//Hide "WooCommerce → Desktop".
	remove_submenu_page('woocommerce', 'wc-admin');
	//Hide "WooCommerce → Orders".
	remove_submenu_page('woocommerce', 'edit.php?post_type=shop_order');
	//Hide "WooCommerce → Coupons".
	remove_submenu_page('woocommerce', 'edit.php?post_type=shop_coupon');
	//Hide "WooCommerce → Customers".
	remove_submenu_page('woocommerce', 'wc-admin&path=/customers');
	//Hide "WooCommerce → Reports".
	remove_submenu_page('woocommerce', 'wc-reports');
	//Hide "WooCommerce → Settings".
	remove_submenu_page('woocommerce', 'wc-settings');
	//Hide "WooCommerce → Status".
	remove_submenu_page('woocommerce', 'wc-status');
	//Hide "WooCommerce → Extensions".
	remove_submenu_page('woocommerce', 'wc-addons');
	//Hide "Products".
	remove_menu_page('edit.php?post_type=product');
	//Hide "Products → All products".
	remove_submenu_page('edit.php?post_type=product', 'edit.php?post_type=product');
	//Hide "Products → Add new".
	remove_submenu_page('edit.php?post_type=product', 'post-new.php?post_type=product');
	//Hide "Products → Categories".
	remove_submenu_page('edit.php?post_type=product', 'edit-tags.php?taxonomy=product_cat&post_type=product');
	//Hide "Products → Tags".
	remove_submenu_page('edit.php?post_type=product', 'edit-tags.php?taxonomy=product_tag&post_type=product');
	//Hide "Products → Attributes".
	remove_submenu_page('edit.php?post_type=product', 'product_attributes');
	//Hide "Analytics".
	remove_menu_page('wc-admin&path=/analytics/revenue');
	//Hide "Analytics → Revenues".
	remove_submenu_page('wc-admin&path=/analytics/revenue', 'wc-admin&path=/analytics/revenue');
	//Hide "Analytics → Orders".
	remove_submenu_page('wc-admin&path=/analytics/revenue', 'wc-admin&path=/analytics/orders');
	//Hide "Analytics → Products".
	remove_submenu_page('wc-admin&path=/analytics/revenue', 'wc-admin&path=/analytics/products');
	//Hide "Analytics → Categories".
	remove_submenu_page('wc-admin&path=/analytics/revenue', 'wc-admin&path=/analytics/categories');
	//Hide "Analytics → Coupons".
	remove_submenu_page('wc-admin&path=/analytics/revenue', 'wc-admin&path=/analytics/coupons');
	//Hide "Analytics → Taxes".
	remove_submenu_page('wc-admin&path=/analytics/revenue', 'wc-admin&path=/analytics/taxes');
	//Hide "Analytics → Downloads".
	remove_submenu_page('wc-admin&path=/analytics/revenue', 'wc-admin&path=/analytics/downloads');
	//Hide "Analytics → Stock".
	remove_submenu_page('wc-admin&path=/analytics/revenue', 'wc-admin&path=/analytics/stock');
	//Hide "Analytics → Settings".
	remove_submenu_page('wc-admin&path=/analytics/revenue', 'wc-admin&path=/analytics/settings');
}
add_action('admin_menu', 'hostfree_hide_woo_menus', 71);

如何隱藏 Woocommerce Metaboxes

/** Hide meta box Woocommerce from edit product and edit order **/
function hostfree_hide_woo_metas() {
	$screen = get_current_screen();
	if ( !$screen ) {
		return;
	}
	//Hide Products Data metabox
	remove_meta_box('woocommerce-product-data', $screen->id, 'normal');
	//Hide Short Description Product Data metabox
	remove_meta_box('postexcerpt', $screen->id, 'normal');
	//Hide Product Gallery metabox
	remove_meta_box('woocommerce-product-images', $screen->id, 'side');
	//Hide Coupon data metabox
	remove_meta_box('woocommerce-coupon-data', $screen->id, 'normal');
	//Hide Order data metabox
	remove_meta_box('woocommerce-order-data', $screen->id, 'normal');
	//Hide Order Items metabox
	remove_meta_box('woocommerce-order-items', $screen->id, 'normal');
	//Hide Downloadable Product Permissions metabox
	remove_meta_box('woocommerce-order-downloads', $screen->id, 'normal');
	//Hide Order Actions metabox
	remove_meta_box('woocommerce-order-actions', $screen->id, 'side');
	//Hide Order Notes metabox
	remove_meta_box('woocommerce-order-notes', $screen->id, 'side');
}
add_action('add_meta_boxes', 'hostfree_hide_woo_metas', 20);

如何從 Woocommerce 隱藏儀表板小工具

/** Hide dashboard widgets from Woocommerce **/
function hostfree_hide_woo_dash_widgets() {
	$screen = get_current_screen();
	if ( !$screen ) {
		return;
	}
	//Remove Recent reviews widget
	remove_meta_box('woocommerce_dashboard_recent_reviews', 'dashboard', 'normal');
	//Remove Woocommerce Status widget
	remove_meta_box('woocommerce_dashboard_status', 'dashboard', 'normal');
}
add_action('wp_dashboard_setup', 'hostfree_hide_woo_dash_widgets', 20);

如何隱藏集成的 Woocommerce 管理界面

/** Remove integrated Woocommerce admin interface **/
add_filter( 'woocommerce_admin_disabled', '__return_true' );

如何隱藏有關您連接到 Woocommerce.Com 的消息

/** Hide connecting to woocommerce.com messages **/
add_filter( 'woocommerce_helper_suppress_admin_notices', '__return_true' );

我應該把這些代碼放在哪裡

最簡單的方法就是複製你想要的 code,然後貼在你的  functions.php 中。

我應該如何使用它們

如果有你不想要隱藏的元素,你可以刪除或是加上註釋(在前面添加 //)在您不想隱藏的功能上:

//remove_meta_box('woocommerce-order-downloads', $screen->id, 'normal');
分享你的喜愛

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *