Home Forums Backend Issues (wp-admin) Cannot update field programmatically


Cannot update field programmatically

  • Hello,
    I am struggling with setting up True/False field value.

    I have simple function that should set field “objednavka_upravena” to true and set checked status in admin when order status changes:

    function eda_zmena_stavu_objednavky( $order_id, $old_status, $new_status,$order ){
    update_field(‘objednavka_upravena’, 1,$order_id);

    add_action( ‘woocommerce_order_status_changed’, ‘eda_zmena_stavu_objednavky’, 99, 4 );

    However, the field not updated.

    Can you help please?

    Thanks for any suggestions.

  • Try using the field key instead of the field name, explained in the doc

  • Thanks for quick reply, I tried to use key instead of name, but it did not worked.

    Do you have any clue why?


  • What does $order_id refer to? Is this the post ID of the order post?

    I don’t know that much about the part of WC that you are trying to alter, but the only other thing that I can think of is that the field you are trying to update does not match up with the value in $order_id.

    Either that or you are trying to update some type of sub field.

  • @hube2 yes, it’s kind of hard to know what it refers to, my guess is the order ID of the WC order that was just placed.

    I would rule out that your hooked function is being called, try this below the function definition:

    var_dump( $order_id );
    var_dump( $old_status );
    var_dump( $new_status );
    wp_die( var_dump( order ) );

    Do you get any output? (remember to set this in wp-config.php):

    define('WP_DEBUG', true);
    define('WP_DEBUG_LOG', true);
    define('WP_DEBUG_DISPLAY', true);
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.