{"id":238,"date":"2020-08-06T14:10:24","date_gmt":"2020-08-06T14:10:24","guid":{"rendered":"https:\/\/demo.wpartisan.net\/developmentsite\/woocommerce-add-order-note\/"},"modified":"2024-11-04T03:57:38","modified_gmt":"2024-11-04T03:57:38","slug":"woocommerce-add-order-note","status":"publish","type":"quick-tips","link":"https:\/\/demo.wpartisan.net\/developmentsite\/woocommerce-add-order-note\/","title":{"rendered":"WooCommerce add order note programmatically"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">To add a custom order note programmatically with the WooCommerce order, which will show on the admin order details page, we need to add an order note when a user has completed the WooCommerce checkout process. We can do this using the &#8216;woocommerce_thankyou&#8217; action hook like the one below:<\/p>\n\n\n\n<pre class=\"wp-block-code \\&quot;wp-block-code\\&quot;\"><code lang=\"\\&quot;php\\&quot;\" class=\"language-\\&quot;php\\&quot;\">function add_custom_order_notes( $order_id ) {\n\t\n\t$order = wc_get_order(  $order_id );\n\t\n\t\/\/ Text for the note\n\t$note = __(\"This is my test note\", 'text-domain');\n\n\t\/\/ Add note\n\t$order->add_order_note( $note );\n}; \n\nadd_action( 'woocommerce_thankyou', 'add_custom_order_notes', 10, 1 ); <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">When the user completes the checkout process, the user is redirected to the WooCommerce thank you page, and then an action hook named woocommerce_thankyou is run. So the attached callback functions with that action hook can perform some tasks, as I showed above. First, it calls the wc_get_order( $order_id ) function to get the $order object and then calls a function name add_order_note() associated with that $order object to add the order note.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the order details page right sidebar area on the admin screen, you can see the order note likes below : <\/p>\n\n\n\n<figure class=\"wp-block-image size-full \\&quot;wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"410\" height=\"406\" src=\"https:\/\/demo.wpartisan.net\/developmentsite\/wp-content\/uploads\/2020\/08\/order-note-on-order-details.png\" alt=\"\" class=\"wp-image-2279\" srcset=\"https:\/\/demo.wpartisan.net\/developmentsite\/wp-content\/uploads\/2020\/08\/order-note-on-order-details.png 410w, https:\/\/demo.wpartisan.net\/developmentsite\/wp-content\/uploads\/2020\/08\/order-note-on-order-details-300x297.png 300w, https:\/\/demo.wpartisan.net\/developmentsite\/wp-content\/uploads\/2020\/08\/order-note-on-order-details-150x150.png 150w\" sizes=\"auto, (max-width: 410px) 100vw, 410px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>To add a custom order note programmatically in the WooCommerce admin order details page, we need to add an order note when the user has completed the WooCommerce checkout process using the &#8216;woocommerce_thankyou&#8217; action hook.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}}},"tags":[],"topics":[43,44,45],"class_list":["post-238","quick-tips","type-quick-tips","status-publish","hentry","topics-woocommerce","topics-woocommerce-query","topics-wordpress"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"WPArtisan","author_link":"https:\/\/demo.wpartisan.net\/developmentsite\/author\/developmentsiteauth\/"},"uagb_comment_info":0,"uagb_excerpt":"To add a custom order note programmatically in the WooCommerce admin order details page, we need to add an order note when the user has completed the WooCommerce checkout process using the 'woocommerce_thankyou' action hook.","_links":{"self":[{"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/quick-tips\/238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/quick-tips"}],"about":[{"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/types\/quick-tips"}],"author":[{"embeddable":true,"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/comments?post=238"}],"wp:attachment":[{"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/media?parent=238"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/tags?post=238"},{"taxonomy":"topics","embeddable":true,"href":"https:\/\/demo.wpartisan.net\/developmentsite\/wp-json\/wp\/v2\/topics?post=238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}