Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Add a WooCommerce custom order action
<?php // only copy if needed
* Add a custom action to order actions select box on edit order page
* Only added for paid orders that haven't fired this action yet
* @param array $actions order actions array to display
* @return array - updated actions
function sv_wc_add_order_meta_box_action( $actions ) {
global $theorder;
// bail if the order has been paid for or this action has been run
if ( ! $theorder->is_paid() || get_post_meta( $theorder->id, '_wc_order_marked_printed_for_packaging', true ) ) {
return $actions;
// add "mark printed" custom action
$actions['wc_custom_order_action'] = __( 'Mark as printed for packaging', 'my-textdomain' );
return $actions;
add_action( 'woocommerce_order_actions', 'sv_wc_add_order_meta_box_action' );
* Add an order note when custom action is clicked
* Add a flag on the order to show it's been run
* @param \WC_Order $order
function sv_wc_process_order_meta_box_action( $order ) {
// add the order note
$message = sprintf( __( 'Order information printed by %s for packaging.', 'my-textdomain' ), wp_get_current_user()->display_name );
$order->add_order_note( $message );
// add the flag so this action won't be shown again
update_post_meta( $order->id, '_wc_order_marked_printed_for_packaging', 'yes' );
add_action( 'woocommerce_order_action_wc_custom_order_action', 'sv_wc_process_order_meta_box_action' );

This comment has been minimized.

Copy link

peratik commented Feb 20, 2017

On sv_wc_process_order_meta_box_action function, how possible display a message box to admin ?

Currently code uses update_post_meta function and add_order_note method and not display any message to admin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.