-
-
Save nazi98/987809f0d752e11d9e88e48ea3e1307d to your computer and use it in GitHub Desktop.
remove all order notes after completed wocommerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Delete Change Status Order Note For Completed | |
add_action( 'woocommerce_order_note_added', 'action_remove_order_note_for_completed', 20, 2); | |
function action_remove_order_note_for_completed($comment_id, $order) { | |
if ( $order->has_status('completed') ) { | |
wc_delete_order_note($comment_id); | |
} | |
} | |
// Delete All internal Order Note after Completed Order | |
add_action('woocommerce_order_status_completed', 'action_remove_order_notes_after_completed', 90, 1); | |
function action_remove_order_notes_after_completed($order_id) | |
{ | |
$notes = wc_get_order_notes([ | |
'order_id' => $order_id, | |
# 'type' => 'internal' | |
]); | |
foreach($notes as $note) { | |
/** | |
array(1) { | |
[0]=> | |
object(stdClass)#35000 (5) { | |
["id"]=> | |
int(2729620) | |
["date_created"]=> | |
object(WC_DateTime)#34998 (4) { | |
["utc_offset":protected]=> | |
int(0) | |
["date"]=> | |
string(26) "2024-10-22 15:11:33.000000" | |
["timezone_type"]=> | |
int(3) | |
["timezone"]=> | |
string(11) "Asia/Tehran" | |
} | |
["content"]=> | |
string(80) "پرداخت موفقیت آمیز بود . | |
کد رهگیری : 59937478701" | |
["customer_note"]=> | |
bool(true) | |
["added_by"]=> | |
string(6) "system" | |
} | |
} | |
*/ | |
wc_delete_order_note($note->id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment