Skip to content

Instantly share code, notes, and snippets.

@woogists
Created March 11, 2018 15:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save woogists/9bc6e4b0de1eeeb53395596729ca5a3f to your computer and use it in GitHub Desktop.
Save woogists/9bc6e4b0de1eeeb53395596729ca5a3f to your computer and use it in GitHub Desktop.
[Customizing checkout fields using actions and filters] Save WooCommerce custom checkout field
/**
* Update the order meta with field value
*/
add_action( 'woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta' );
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ( ! empty( $_POST['my_field_name'] ) ) {
update_post_meta( $order_id, 'My Field', sanitize_text_field( $_POST['my_field_name'] ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment