Support

Account

Home Forums General Issues Custom Field (Woocommerce) value => load as acf deafault_value

Solved

Custom Field (Woocommerce) value => load as acf deafault_value

  • Hi i will load a custom field Value (from woocommerce) into the acf InputField as default_value.

    But it doesn’t work

    I wrote this in my functions.php

    function my_acf_update_value( $value, $post_id, $field ) {

    $post_id = $order->id;
    $acfstrasse = get_field_object($field_key, $post_id);
    $acfstrasse[‘default_value’] = get_post_meta( $order->id, ‘Strasse’, true );

    return $acfstrasse;

    }

    add_filter(‘acf/update_value/key=field_56572463a9ac7’, ‘my_acf_update_value’, 10, 3);

    with:

    <?php /* ACF Test*/
    $field_key = “field_56572463a9ac7”;
    $post_id = $order->id;
    $acfstrasse = get_field_object($field_key, $post_id);
    $acfstrasse[‘default_value’] = get_post_meta( $order->id, ‘Strasse’, true );

    echo $acfstrasse[‘label’] . ‘: ‘ . $acfstrasse[‘value’] . ‘|’ . $acfstrasse[‘default_value’];

    ?>

    I see the Value of the custom Field Strasse

  • please use code tags when posting code.

    I’m not sure exactly what you’re doing, but if you want to set the default value of a field then I think you need to use the acf/load_field filter. the acf/update_value runs when before the acf field is saved, not when the field is loaded.

    http://www.advancedcustomfields.com/resources/acfload_field/

    You can’t change the default value of an ACF field when you’re saving a product in woocommerce.

    Also, looking at what I can make out of your code $order->id has no meaning inside of the function.

    $post_id = $order->id; is setting $post_id to NULL.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Custom Field (Woocommerce) value => load as acf deafault_value’ is closed to new replies.