Disable (remove) the marketing menu option in WooCommerce 4.3.x

ぐ巨炮叔叔 提交于 2021-01-01 04:24:00

问题


Since the release of WooCommerce 4.3.x, the previous fix for removing the Marketing menu option that worked with 4.1.x does not work anymore and I'm wondering if anyone knows how to remove it for 4.3.x.

I've tried all of these without success:

#1:

add_filter( 'woocommerce_marketing_menu_items', '__return_empty_array' );

#2:

add_action( 'admin_init', 'remove_wc_marketing_menu_item' );
    function remove_wc_marketing_menu_item() {
    remove_menu_page( 'admin.php?page=wc-admin&path=/marketing' );
}

#3:

add_action( 'admin_init', 'remove_wc_marketing_menu_item' );
    function remove_wc_marketing_menu_item() {
    remove_menu_page( 'wc-admin&path=/marketing' );
}

#4:

add_filter( 'woocommerce_marketing_menu_items', 'remove_wc_marketing_menu_item' );
    function remove_wc_marketing_menu_item( $marketing_pages ) {
    return array();
}

None of them work with the latest WP and WC. I have no other plugins installed and I'm not using a customized child theme or anything like that.

All ideas are welcome.


回答1:


The FeaturePlugin.php contains on line 292-301

/**
 * Overwrites the allowed features array using a local `feature-config.php` file.
 *
 * @param array $features Array of feature slugs.
 */
public function replace_supported_features( $features ) {
    $feature_config = apply_filters( 'woocommerce_admin_get_feature_config', wc_admin_get_feature_config() );
    $features       = array_keys( array_filter( $feature_config ) );
    return $features;
}

So you get: (Tested in WooCommerce 4.3.1 version)

function filter_woocommerce_admin_get_feature_config( $feature_config ) {   
    $feature_config['marketing'] = false;

    return $feature_config;
}
add_filter( 'woocommerce_admin_get_feature_config', 'filter_woocommerce_admin_get_feature_config', 10, 1 );

Source: https://gist.github.com/isaumya/89f48dcd84cb58af1e668bb76ba2c029 - https://github.com/woocommerce/woocommerce-admin/issues/4716

Available as a plugin: https://wordpress.org/plugins/disable-dashboard-for-woocommerce/




回答2:


remove_menu_page( 'woocommerce-marketing' );



来源:https://stackoverflow.com/questions/63068812/disable-remove-the-marketing-menu-option-in-woocommerce-4-3-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!