Skip to content
Advertisement

Enable ‘Read only’ on order page (WooCommerce) for order created & customer email for shop manager only

I’m using WooCommerce: Disable Date on Edit Orders anwer code

According to this only applies to admin, how about for only shop manager?

I wonder is there any way where I can disable on edit ‘Order created & ‘Customer:’? for shop manager only?

Because the code provided does not work for me and only apply to admin. The way I’m doing is using plugin ‘Simple Custom CSS and JS’ and add accordingly using the code provided. But it doesn’t work.

Is there any tips or code that can be directly be added to functions.php?

As in the post provided to disable edit on ‘order created’, how about for ‘Customer:’? which is right below the ‘Status’.

Advertisement

Answer

First create js file in your active parent/child theme

Add the code:

jQuery(function($) {
     $('.order_data_column .date-picker').attr("disabled", true);
     $('.order_data_column .hour').attr("disabled", true);
     $('.order_data_column .minute').attr("disabled", true);
     $('.wc-customer-user select').attr("disabled", true);
 });

In your functions.php file add this:

function prevent_editing_shop_order_fields( $current_screen ) {
    $user = wp_get_current_user();
    if ( 'shop_order' == $current_screen->post_type && 'post' === $current_screen->base && isset( $user->roles[0] ) && $user->roles[0] == 'shop_manager' ) { 
        // Fix accordingly with your file
        wp_enqueue_script('myscript', get_stylesheet_directory_uri().'/assets/js/scripts.js',array('jquery')); 
    }
}
add_action( 'current_screen', 'prevent_editing_shop_order_fields' );

$user->roles[0] == ‘shop_manager’ – is a condition to check if current user is shop_manager role

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement