Menus > Pages add_action('admin_init', array( $this, 'add_nav_menu_meta_boxes' ) ); } /** * Add menu items */ public function admin_menu() { global $menu; if ( current_user_can( 'manage_woocommerce' ) ) { $menu[] = array( '', 'read', 'separator-woocommerce', '', 'wp-menu-separator woocommerce' ); } add_menu_page( __( 'WooCommerce', 'woocommerce' ), __( 'WooCommerce', 'woocommerce' ), 'manage_woocommerce', 'woocommerce', null, null, '55.5' ); add_submenu_page( 'edit.php?post_type=product', __( 'Shipping Classes', 'woocommerce' ), __( 'Shipping Classes', 'woocommerce' ), 'manage_product_terms', 'edit-tags.php?taxonomy=product_shipping_class&post_type=product' ); add_submenu_page( 'edit.php?post_type=product', __( 'Attributes', 'woocommerce' ), __( 'Attributes', 'woocommerce' ), 'manage_product_terms', 'product_attributes', array( $this, 'attributes_page' ) ); } /** * Add menu item */ public function reports_menu() { add_submenu_page( 'woocommerce', __( 'Reports', 'woocommerce' ), __( 'Reports', 'woocommerce' ) , 'view_woocommerce_reports', 'wc-reports', array( $this, 'reports_page' ) ); } /** * Add menu item */ public function settings_menu() { $settings_page = add_submenu_page( 'woocommerce', __( 'WooCommerce Settings', 'woocommerce' ), __( 'Settings', 'woocommerce' ) , 'manage_woocommerce', 'wc-settings', array( $this, 'settings_page' ) ); add_action( 'load-' . $settings_page, array( $this, 'settings_page_init' ) ); } /** * Loads gateways and shipping methods into memory for use within settings. */ public function settings_page_init() { WC()->payment_gateways(); WC()->shipping(); } /** * Add menu item */ public function status_menu() { add_submenu_page( 'woocommerce', __( 'WooCommerce Status', 'woocommerce' ), __( 'System Status', 'woocommerce' ) , 'manage_woocommerce', 'wc-status', array( $this, 'status_page' ) ); register_setting( 'woocommerce_status_settings_fields', 'woocommerce_status_options' ); } /** * Addons menu item */ public function addons_menu() { add_submenu_page( 'woocommerce', __( 'WooCommerce Add-ons/Extensions', 'woocommerce' ), __( 'Add-ons', 'woocommerce' ) , 'manage_woocommerce', 'wc-addons', array( $this, 'addons_page' ) ); } /** * Highlights the correct top level admin menu item for post type add screens. */ public function menu_highlight() { global $menu, $submenu, $parent_file, $submenu_file, $self, $post_type, $taxonomy; $to_highlight_types = array( 'shop_order', 'shop_coupon' ); if ( isset( $post_type ) ) { if ( in_array( $post_type, $to_highlight_types ) ) { $submenu_file = 'edit.php?post_type=' . esc_attr( $post_type ); $parent_file = 'woocommerce'; } if ( 'product' == $post_type ) { $screen = get_current_screen(); if ( $screen->base == 'edit-tags' && taxonomy_is_product_attribute( $taxonomy ) ) { $submenu_file = 'product_attributes'; $parent_file = 'edit.php?post_type=' . esc_attr( $post_type ); } // Fix the highlight of shipping classes menu if ( 'product_shipping_class' == $screen->taxonomy && $parent_file == 'edit.php?post_type=product' ) { $submenu_file = 'edit-tags.php?taxonomy=product_shipping_class&post_type=product'; } } } if ( isset( $submenu['woocommerce'] ) && isset( $submenu['woocommerce'][1] ) ) { $submenu['woocommerce'][0] = $submenu['woocommerce'][1]; unset( $submenu['woocommerce'][1] ); } if ( isset( $submenu['woocommerce'] ) && current_user_can( 'manage_woocommerce' ) ) { foreach ( $submenu['woocommerce'] as $key => $menu_item ) { if ( 0 === strpos( $menu_item[0], _x( 'Orders', 'Admin menu name', 'woocommerce' ) ) ) { $menu_name = _x( 'Orders', 'Admin menu name', 'woocommerce' ); if ( $order_count = wc_processing_order_count() ) { $menu_name .= ' ' . number_format_i18n( $order_count ) . ''; } $submenu['woocommerce'][ $key ] [0] = $menu_name; break; } } } } /** * Reorder the WC menu items in admin. * * @param mixed $menu_order * @return array */ public function menu_order( $menu_order ) { // Initialize our custom order array $woocommerce_menu_order = array(); // Get the index of our custom separator $woocommerce_separator = array_search( 'separator-woocommerce', $menu_order ); // Get index of product menu $woocommerce_product = array_search( 'edit.php?post_type=product', $menu_order ); // Loop through menu order and do some rearranging foreach ( $menu_order as $index => $item ) { if ( ( ( 'woocommerce' ) == $item ) ) { $woocommerce_menu_order[] = 'separator-woocommerce'; $woocommerce_menu_order[] = $item; $woocommerce_menu_order[] = 'edit.php?post_type=product'; unset( $menu_order[$woocommerce_separator] ); unset( $menu_order[$woocommerce_product] ); } elseif ( !in_array( $item, array( 'separator-woocommerce' ) ) ) { $woocommerce_menu_order[] = $item; } } // Return order return $woocommerce_menu_order; } /** * Custom menu order * * @return bool */ public function custom_menu_order() { return current_user_can( 'manage_woocommerce' ); } /** * Init the reports page */ public function reports_page() { WC_Admin_Reports::output(); } /** * Init the settings page */ public function settings_page() { WC_Admin_Settings::output(); } /** * Init the attributes page */ public function attributes_page() { WC_Admin_Attributes::output(); } /** * Init the status page */ public function status_page() { WC_Admin_Status::output(); } /** * Init the addons page */ public function addons_page() { WC_Admin_Addons::output(); } /** * Add custom nav meta box * * Adapted from http://www.johnmorrisonline.com/how-to-add-a-fully-functional-custom-meta-box-to-wordpress-navigation-menus/ */ public function add_nav_menu_meta_boxes() { add_meta_box( 'woocommerce_endpoints_nav_link', __( 'WooCommerce Endpoints', 'woocommerce' ), array( $this, 'nav_menu_links' ), 'nav-menus', 'side', 'low' ); } public function nav_menu_links() { $exclude = array( 'view-order', 'add-payment-method', 'order-pay', 'order-received' ); ?>