Support » Developing with WordPress » remove_submenu_page not working

  • I have the following code:

    add_action( 'admin_menu', 'tcd_remove_admin_menus', 999 );
    function tcd_remove_admin_menus() {
        if ( current_user_can('shop_manager')){
       		remove_menu_page('edit.php');   
        	remove_menu_page('upload.php');   
        	remove_menu_page('tools.php');
        	remove_menu_page('edit-comments.php');
            remove_menu_page('users.php');
            remove_menu_page('yikes-woo-settings');
            remove_menu_page('wpseo_workouts');
            remove_menu_page('edit.php?post_type=product');
            remove_menu_page('edit.php?post_type=page');
            remove_menu_page( 'avada' );
            remove_menu_page( 'wc-admin&path=/analytics/overview' );
            remove_submenu_page('woocommerce', 'wc-admin');
            
            remove_submenu_page('woocommerce-marketing', 'edit_shop_coupons');
    	}
    }

    and the only line that doesn’t work is remove_submenu_page(‘wc-admin’, ‘edit_shop_coupons’); I’ve tried multiple things but no success…

    I am trying to remove a submenu Under Marketing (admin.php?page=wc-admin&path=/marketing) > Coupons (edit.php?post_type=shop_coupon)

    Then I added a code to return the submenus array and I got this:

        [woocommerce-marketing] => Array
            (
                [0] => Array
                    (
                        [0] => Overview
                        [1] => view_woocommerce_reports
                        [2] => admin.php?page=wc-admin&path=/marketing
                        [3] => Overview
                    )
    
                [1] => Array
                    (
                        [0] => Coupons
                        [1] => edit_shop_coupons
                        [2] => edit.php?post_type=shop_coupon
                        [3] => Coupons
                    )
    
                [2] => Array
                    (
                        [0] => Gift Cards
                        [1] => manage_woocommerce
                        [2] => gc_giftcards
                        [3] => Gift Cards
                    )
    
                [3] => Array
                    (
                        [0] => Activity
                        [1] => manage_woocommerce
                        [2] => gc_activity
                        [3] => Activity
                        [4] => hide-if-js
                    )
    
            )

    How can I remove Array[1] from the menu?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator t-p

    (@t-p)

    I recommend getting in touch with WooCommerce’s support about this via https://woocommerce.com/my-account/create-a-ticket/ if you have any of their paid WooCommerce products or https://wordpress.org/support/plugin/woocommerce/ if you do not.

    Thread Starter Cezar Ayran

    (@ayrancd)

    @t-p this is not just a WooCommerce question, I am using WP functions, as you can see the code has tons of removals and they are NOT all related to WooCommerce anyway.. I posted the same question on Woo plugin forum.

    • This reply was modified 16 hours, 23 minutes ago by Cezar Ayran.
    Moderator t-p

    (@t-p)

    You may try asking at your theme’s dedicated support.

    Moderator bcworkz

    (@bcworkz)

    Hi Cezar!

    It could be the submenu was added after your removal code had already run.

    How can I remove Array[1] from the menu?

    What hook did you use to get the $submenu array output? Using remove_submenu_page() from there ought to work. Or you could directly unset the undesired element. Something like:

    global $submenu;
    unset($submenu['woocommerce-marketing'][1]);

    But I’d recommend verifying that element [1] is the correct element before unsetting it.

    A totally different approach would be to simply hide undesired elements with CSS.

    Note that removing a submenu element does not prevent access to the related resource. It does make it difficult to learn the correct URL. But if the URL is known, access is possible, menu item or not.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.