Skip to content

Instantly share code, notes, and snippets.

@Neshable
Created February 27, 2019 07:15
Show Gist options
  • Save Neshable/266abafe4c753051439b68d728edc760 to your computer and use it in GitHub Desktop.
Save Neshable/266abafe4c753051439b68d728edc760 to your computer and use it in GitHub Desktop.
WooCommerce Add Custom Fields to Order
if ( ! function_exists('custom_meta_to_order') ) {
add_action('woocommerce_checkout_update_order_meta', 'custom_meta_to_order', 20, 1);
function custom_meta_to_order( $order_id ) {
$order = wc_get_order( $order_id );
$order->update_meta_data( '_order_custom_field', 'value' );
$order->save();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment