Developer hooks

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)
Was this page helpful?