Update:
I was able to show the form using:
add_action( 'woocommerce_after_order_notes', 'checkout_date_time_field', 10, 1 );
function checkout_date_time_field( $checkout ) {
echo '<div><h2>Date & Time</h2>';
echo acfe_form('date_time');
echo '</div>';
}
and save the values using this code after removing all dynamic form post actions:
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['acf']['field_5e9b33aa85f9c'] ) ) {
update_post_meta( $order_id, 'date_time', 'field_5e9b33aa85f9c' );
}}
I hope this will help someone.
Well, that solution won’t work, it only saves the current date/time
Hello,
Thanks for the feedback. ACF & ACF Extended have no specific compatibility features with Woocommerce. But as Woocommerce use WP Post Meta, you can possibly make it work with ACF.
I haven’t tested your code, but it looks like there is a problem in your update_post_meta()
function.
Here is a usage example: update_post_meta($order_id, 'my_field', 'my_value')
(Reference: https://developer.wordpress.org/reference/functions/update_post_meta/)
In your code, the value is field_5e9b33aa85f9c
which seems strange, you should probably check that.
Note: I plan to add Woocommerce compatibility features in the future, no ETA yet tho.
Hope it helps!
Have a nice day.
Regards.
Hi,
Thanks for the reply,
I was finally able to save the submitted value using this code:
add_action('woocommerce_checkout_update_order_meta', 'checkout_date_time_field_update_order_meta');
function checkout_date_time_field_update_order_meta( $order_id ) {
$field_name = 'date_time_1';
$field_value = $_POST['acf']['field_5e9b33aa85f9c'];
if ( ! empty( $field_value ) ) {
update_post_meta( $order_id, $field_name , $field_value );
}
this will also work using update_field( $field_name, $field_value, $order_id);
instead of update_post_meta
I needed to use $_POST['acf']['field_key']
in order to get the submitted value.
I hope this helps someone too.
Many Thanks.
Hello,
I’m glad to hear that you made it work 🙂
Just a side note: update_field()
function should be used with ACF fields, not other unrelated meta. So you should stick to update_post_meta()
function.
Have a nice day!
Regards.