How to allow other user roles to access shipment container.

Add this code to your child theme’s functions.php file:


function custom_user_role_access_container( $allowed_role ){
    /*
     * Default Allowed roles
     *  - administrator
     *  - wpcargo_employee
     */
    $allowed_role[] = 'my_new_role'; // Add new role to access shipment container
    return $allowed_role
}
add_filter( 'wpcsc_allowed_users', 'custom_user_role_access_container', 10, 1 );

Add this code to only show shipments created by or assigned to current user:


function wpcsc_get_unassigned_shipment_sql_callback( $sql, $per_page){
    global $wpdb;
    $current_user = wp_get_current_user();
    $current_user_id = $current_user->ID;
    if( in_array( 'administrator', $current_user->roles ) ){
        return $sql;
    }
    $assigned_shipments = get_option('container_assigned_shipments');
    $shipment_status = '';
    if( !empty( $assigned_shipments ) ){
        $shipment_status = implode("','", $assigned_shipments );
    }else{
        $shipment_status = 'Pending';
	}
	/*
	 * assign_user_field Field map
	 * Employee = registered_employee
	 * Agent 	= agent_fields
	 * Client 	= registered_shipper
	 * Driver 	= wpcargo_driver
	 */ 
	
	 $assign_user_field = 'agent_fields';
	
    $sql = "SELECT tbl1.ID FROM `$wpdb->posts` tbl1
    LEFT JOIN `$wpdb->postmeta` tbl2 ON tbl1.ID=tbl2.post_id AND tbl2.meta_key='shipment_container'
    LEFT JOIN `$wpdb->postmeta` tbl3 ON tbl1.ID=tbl3.post_id AND tbl3.meta_key='wpcargo_status'
    LEFT JOIN `$wpdb->postmeta` tbl4 ON tbl1.ID=tbl4.post_id AND tbl4.meta_key='".$assign_user_field."'
    WHERE post_status='publish' AND post_type='wpcargo_shipment'
    AND ( tbl2.meta_key IS NULL OR tbl2.meta_value LIKE '' )
    AND tbl3.meta_value IN ('".$shipment_status."')
    AND tbl4.meta_value = ".$current_user_id."
    ORDER BY tbl1.post_title ASC";
    if( (int)$items_per_page != 0 ){
        $sql .= " LIMIT ".(int)$items_per_page;
    }
    return $sql;
}
add_filter( 'wpcsc_get_unassigned_shipment_sql', 'wpcsc_get_unassigned_shipment_sql_callback', 10, 2 );

NOTE:
User Role Slugs
WPCargo Agent: cargo_agent
Shipment Manager: wpc_shipment_manager
WPCargo Client: wpcargo_client
WPCargo Driver: wpcargo_driver

Meta Keys
registered_employee
registered_shipper
agent_fields
wpcargo_branch_manager
wpcargo_driver

0
    0
    Your Cart
    Your cart is emptyReturn to Shop