I am working on a way our sales team can mark orders as manual and check back on them. We are using the HPOS system. I need to be able to update the field value when the update/publish button is clicked. Here is what I have:
function update_manual_order( $order_id, 'manual_order', $value = '' ) {
$order = wc_get_order( $order_id );
$order = get_meta( 'manual_order' );
if ( empty( $value ) ) {
$order = update_meta_data( $post_id, $field_name, '0' );
} else {
$order = update_meta_data( $post_id, $field_name, '1' );
}
$order->update_meta_data( 'manual_order', $manual_order_option );
//$order->save();
}
add_action( 'woocommerce_process_shop_order_meta', 'update_manual_order', 60 );
The field is currently a checkbox, false would be 0 and true would be 1. As for the checkbox format, it is visually a toggle but here are the lines:
<input type="checkbox" id="toggle" class="checkbox" name="manual_order" value="' . checked( 1, get_option( 'manual_order' ), false ) . '" /> <label for="toggle" class="switcher"></label>
I want to be able to update the field with the updates and sync the current order meta value. Is there something I am missing? I am not too familiar with the new system, any help would be much appreciated!
I attempted to use the new HPOS documentation to have it find the field and use that to add/update the meta field. Current code results in a critical error.
Alexandra Chavez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.