Viewing documentation for the User Notes Plugin
Developer
Accessing User Notes
User Notes are stores as an array on the user meta. The below example shows you how to output the user notes via PHP.
function custom_get_notes( $user_id ) {
if ( empty( $user_id ) ) {
return;
}
$notes = get_user_meta( $user_id, '_puri_user_note', true );
if ( empty( $notes ) || ! is_array( $notes ) ) {
return;
}
$notes_output = '';
foreach ( $notes as $note ) {
if ( ! empty( $note['content'] ) ) {
$notes_output .= esc_html( $note['content'] );
}
}
if ( empty( $notes_output ) ) {
return;
}
$output = '<span style="margin:20px 0px;display: block;">';
$output .= '<strong>' . __( 'Private Notes:', 'puri-user-notes' ) . '</strong>';
$output .= $notes_output;
$output .= '</span>';
return $output;
}
Code language: PHP (php)
Enable WooCommerce Order Column Notes
In some cases you may need to specify at which action the filter should run. If you are using another plugin, please select “plugins _loaded” with a priority of 5.
Otherwise this snippet should activate private notes in the WooCommerce orders list column.
function custom_after_plugins_loaded() {
add_filter( 'puri_user_notes_enable_wc_column', '__return_true' );
}
add_action( 'plugins_loaded', 'custom_after_plugins_loaded', 5 );
Code language: JavaScript (javascript)
Reorder the WooCommerce columns to the end
// Sort columns after they have all been added by plugins.
function custom_wc_column_order($columns) {
if (!empty($columns['private_user_note'])) {
// Grab the note column.
$note_column = $columns['private_user_note'];
// Remove it from the current location in the array.
unset($columns['private_user_note']);
// Re-set it at the end.
$columns['private_user_note'] = $note_column;
}
return $columns;
}
add_filter('manage_edit-shop_order_columns', 'custom_wc_column_order', 999);
Code language: PHP (php)
Register Custom User Role
In this example the order_manager
is a custom user role added by another plugin. You can register the user role with Private User Note, to allow them to view & edit user notes.
function add_order_manager_to_allowed_roles( $allowed_roles ) {
// Add 'order_manager' to the array of allowed roles
$allowed_roles[] = 'order_manager';
return $allowed_roles;
}
// Hook the above function to the 'user_notes_manager_roles' filter
add_filter( 'user_notes_manager_roles', 'add_order_manager_to_allowed_roles' );
Code language: PHP (php)