0

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'.

7uc1f3r
  • 28,449
  • 17
  • 32
  • 50
Cole
  • 45
  • 5

1 Answers1

0

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

Snuffy
  • 1,723
  • 1
  • 5
  • 9
  • thank you! Does this apply to only user role shop manager? – Cole Sep 29 '21 at 12:31
  • Or apply to admin. If so, how do I add code to apply this only for shop manager? – Cole Sep 29 '21 at 12:40
  • I have updated my answer. In short its loading the file only if its shop manager. – Snuffy Sep 29 '21 at 12:48
  • Thank you. I've tried to create a js file using notepad > paste the code you've provided for js file > save as javascriptfile.js > upload it via FTP to child theme (after upload, from the theme editor shows the javascriptfile.js under active child theme > then paste the below code to function.php. However, I've logged in to shop manager account, and still able to change the order create and customer. May I know where do I did wrong during the process I've stated? – Cole Sep 29 '21 at 15:00
  • function.php should be functions.php file ? – Snuffy Sep 30 '21 at 07:12
  • yes it is. Sorry it's a typo – Cole Sep 30 '21 at 07:58
  • Please check the screenshot - https://prnt.sc/1u7dafv and confirm you see the script file you create is loaded – Snuffy Sep 30 '21 at 09:17
  • Thank you for your reply. Yes it does have the myscript https://snipboard.io/lytamM.jpg. But it doesn't work. I wonder if you could provide the another code in functions.php without any user role restriction? I may try on this, if it works, it may be due to shop_manager role problem. – Cole Sep 30 '21 at 13:49
  • On my side its working without issues – Snuffy Oct 01 '21 at 06:04