• Resolved mariods


    Hi i use a code to update metadata. With default woocommerce fields the code works fine. With the fields i make with your plugin it returns an internal server error and metadata doenst update.

    I use this code.

    add_action( ‘woocommerce_new_order’, ‘set_city_same_to_state’, 1, 1 );
    function set_city_same_to_state( $order_id ) {

    $order = new WC_Order( $order_id );
    $order->update_meta_data( ‘custom_field’, $order->get_billing_custom());


    Do you know why? Thanks

Viewing 1 replies (of 1 total)
  • Plugin Author ThemeHigh


    The custom fields data are saved in the wp_postmeta table and the value can be retrieved using the below code.

    get_post_meta($order_id, 'field_name', true);

    To update the value, you can use the below code.

    update_post_meta($order_id, 'field_name', $field_value);

    You can also try the below code for updating custom_field_2 with the value of custom_field_1.

    add_action( 'woocommerce_checkout_update_order_meta', 'set_city_same_to_state', 999, 1 );
    function set_city_same_to_state( $order_id ) {
      $field_1_value = get_post_meta($order_id, 'custom_field_1', true);
      update_post_meta($order_id, 'custom_field_2', $field_1_value);

    Also in our plugin, we are using the hook “woocommerce_checkout_update_order_meta“ for saving the metadata for the custom field. This hook trigger after the hook “woocommerce_new_order“ that you have used.

    Hope this will help.

    Thank you!

Viewing 1 replies (of 1 total)
  • The topic ‘Update meta data’ is closed to new replies.