Skip to content

Instantly share code, notes, and snippets.

@jessepearson
Last active July 2, 2020 14:13
Show Gist options
  • Save jessepearson/7c40eb2fc7385a71cc4d676380ddf47c to your computer and use it in GitHub Desktop.
Save jessepearson/7c40eb2fc7385a71cc4d676380ddf47c to your computer and use it in GitHub Desktop.
If order notes are added via AutomateWoo, they do not have a user associated with them. This is an example of how to make it so a user is added to a note added by AW.
<?php // do not copy this line
/**
* Adds hook to the AutomateWoo order paid action to add a filter.
*/
add_action( 'automatewoo/order/paid_async', 'add_automatewoo_note_filter_20200702' );
function add_automatewoo_note_filter_20200702() {
add_filter( 'woocommerce_new_order_note_data', 'add_author_to_automatewoo_note_20200702' );
}
/**
* Filter will take a user id (50) and then add the order note under that user.
*/
function add_author_to_automatewoo_note_20200702( $note_data ) {
$user = get_user_by( 'id', 50 );
$note_data['comment_author'] = $user->display_name;
$note_data['comment_author_email'] = $user->user_email;
return $note_data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment