Remove/hide Paypal Settings tab in Product Data
-
Hello, i’m trying to achieve this:
- Remove/hide all tabs (including PayPal Settings tab) except General tab from the Product Data section; for a specific user ID
To remove them, i use this code via Code Snippets plugin:
add_filter( 'woocommerce_product_data_tabs', 'remove_product_data_tabs_by_slug', 10, 1 );
function remove_product_data_tabs_by_slug( $tabs ) {
// Check the current user ID
$current_user_id = get_current_user_id();
if ( $current_user_id == 3 ) {
// Define the slugs of tabs to be removed
$tabs_to_remove = array(
'inventory_product_data', // Inventory tab
'shipping_product_data', // Shipping tab
'linked_product_data', // Linked Products tab
'product_attributes', // Attributes tab
'variations_product_data', // Variations tab
'advanced_product_data', // Advanced tab
'ppcp_product_data', // Example 3rd-party plugin tab
);
// Remove tabs by matching theirtarget
value
foreach ( $tabs as $key => $tab ) {
if ( isset( $tab['target'] ) && in_array( $tab['target'], $tabs_to_remove ) ) {
unset( $tabs[$key] );
}
}
}
return $tabs;
}
add_action( 'admin_init', 'redirect_user_from_restricted_product_data_tabs' );
function redirect_user_from_restricted_product_data_tabs() {
// Check if the current user is the targeted user
$current_user_id = get_current_user_id();
if ( $current_user_id != 3 ) {
return; // Do nothing for other users
}
// Check if the user is editing a product
global $pagenow;
if ( $pagenow === 'post.php' && isset( $_GET['post'] ) ) {
// Redirect to the WooCommerce Dashboard
$redirect_url = admin_url( 'admin.php?page=wc-admin' );
wp_redirect( $redirect_url );
exit;
}
}Result
1. It successfully removing/hiding the tabs only for specified user ID
2. It’s failed to remove/hide the Paypal Settings tab for specified user ID
Problem
- How can i remove this Paypal Settings tab for specific user ID? The slug is #ppcp_product_data
Trying to explore this forum, stackoverflow but found none. Asked chatgpt but still stuck. Any help is appreciated. Thank you!
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.