Remove WPCargo Status by user role

Note: Copy and paste this code in functions.php of your current theme.

    function custom_wpcargo_history_fields( $history_fields ){
      $status_to_remove = array();
      $current_user = wp_get_current_user();
      /*
       * Modiry your status list to remove here.
       */

      /*
       * WPCargo Roles
       *
       * wpcargo_client
       * wpcargo_pending_client
       * wpcargo_employee
       * cargo_agent
       */

      // List to remove in Agent Role
      if( in_array( 'cargo_agent' , $current_user->roles ) ){
        $status_to_remove = array(
          'Delivered',
          'In Transit'
        );
      }

      // List to remove in Driver Role
      if( in_array( 'wpcargo_driver' , $current_user->roles ) ){
        $status_to_remove = array(
          'Delivered',
          'In Transit'
        );
      }
      

      /*
       * Unset the list of satus here. Note this is no need to modify
       */
      if( !empty( $status_to_remove ) ){
        foreach( $status_to_remove as $status ){
          if ( ($key = array_search( $status, $history_fields['status']['options'])) !== false) {
              unset($history_fields['status']['options'][$key]);
          }
        }
      }
      
      return $history_fields;
    }
    add_filter( 'wpcargo_history_fields', 'custom_wpcargo_history_fields' );
  
0
    0
    Your Cart
    Your cart is emptyReturn to Shop