Support » Plugin: Advanced Custom Fields: Extended » ACF integration with Woocommerce for oders

  • Resolved yourtrustedfreelancer

    (@yourtrustedfreelancer)


    Hi,
    You’re doing great job here, thank you.

    I tried to follow this thread https://wordpress.org/support/topic/acf-form-integration-in-woocommerce-checkout/
    and apply it for woocommerce order. The form is showing correctly on the checkout but I am not able to save the values in the order page.
    I created a group field with day/time picker and added the location rule as post type->order and I did the same for the form but I used a post action instead, which I think it is wrong.
    Do I need to create a custom action or add a woocommerce action hook to update the field, and if so how would I save the form fields to order.
    Thank you again.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter yourtrustedfreelancer

    (@yourtrustedfreelancer)

    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.

    Thread Starter yourtrustedfreelancer

    (@yourtrustedfreelancer)

    Well, that solution won’t work, it only saves the current date/time

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    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.

    Thread Starter yourtrustedfreelancer

    (@yourtrustedfreelancer)

    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.

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    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.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘ACF integration with Woocommerce for oders’ is closed to new replies.