Banner Logo

Be a part of the family: Connect, Receive Support,
Contribute, and Reap Abundant Rewards

Save custom order item field on Woocommerce admin order pages + Vendor Dashboard

MultivendorX

Resolved
Viewing 8 reply threads
  • Author
    Posts
    • #220420
      l.gan
      Participant

      Hello
      Thanks for the great plugin support.
      Could you help me. According to the law in my country, I must provide labeling codes for each item on the receipt.i.e. Before the order reaches the “Completed” status (at this point the final receipt is generated), the supplier must enter labeling codes for the goods that will be shipped to the client (dashboard – vendor-orders – order).

      I found a solution to add codes to the order from the administrator side. This code works and is compatible with HPOS. But I can’t figure out how to add these fields to an order from the supplier’s side.

      I need the supplier to be able to enter marking codes for each item in the order from the moment the order is “in process” to “completed”. Please, help.

      
      // Add a custom field
      add_action( 'woocommerce_before_order_itemmeta', 'add_order_item_custom_field', 10, 2 );
      function add_order_item_custom_field( $item_id, $item ) {
          // Targeting line items type only
          if( $item->get_type() !== 'line_item' ) return;
      
          $post_key = 'cfield_oitem_'.$item_id;
      
          woocommerce_wp_text_input( array(
              'id'            => $post_key,
              'label'         => __( 'Custom Text Field Title', 'text_domain' ),
              'description'   => __( 'Enter the title of your custom text field.', 'text_domain' ),
              'desc_tip'      => true,
              'class'         => 'woocommerce',
              'value'         => $item->get_meta('_custom_field'),
          ) );
      }
      
      // Save the custom field value (Compatible with HPOS)
      add_action('woocommerce_before_save_order_item', 'save_order_item_custom_field_value', 100 );
      function save_order_item_custom_field_value( $item ){
          $post_key = 'cfield_oitem_'.$item->get_id();
      
          if( isset($_POST[$post_key]) ) {
              $item->update_meta_data( '_custom_field', sanitize_text_field($_POST[$post_key]) );
          }
      }
      
      add_filter('woocommerce_order_item_display_meta_key', 'filter_wc_order_item_display_meta_key', 20, 3 );
      function filter_wc_order_item_display_meta_key( $display_key, $meta, $item ) {
          // Change displayed label for specific order item meta key
          if( is_admin() && $item->get_type() === 'line_item' && $meta->key === '_custom_field' ) {
              $display_key = __("Some label", "woocommerce" );
          }
          return $display_key;
      }
      Copy
      code source: https://stackoverflow.com/a/54406630/18203998
      Copy
    • #220429

      @l.gan, We understand your end. But at this time, we’re unable to accommodate your custom request due to limited bandwidth.

      If it were a quick customization that requires a few lines of coding help,we’d happily assist within our free support window. However, the complexity of your request exceeds our current support capabilities.
      Now if you need guidance with the hook/filter please do let us know, we will surely assist you accordingly.

      Alternatively you may reach out to our service team here :https://multivendorx.com/custom-development/ for assistance with your custom requirement. You can also send them a mail on custom.dev@multivendorx.com.

      Thanks for your understanding and let us know if you need any further assistance from our end.

      • #220444
        l.gan
        Participant

        Thank you Sangita,
        Yes
        I need help with a hook/filter.

    • #220446

      Thanks for getting back to us. Our team is looking into this. We will provide you with the hook/filter accordingly. Kindly provide us some time.

      • #220455
        l.gan
        Participant

        I displayed custom_field in the order meta, at least the ability to enter it. but I don’t understand how I can save it?

        add_action( 'mvx_vendor_dash_after_order_itemmeta_table', 'mvx_add_custom_field_to_vendor_order_item', 10, 3 );
        function mvx_add_custom_field_to_vendor_order_item( $item_id, $item, $product ) {
            $post_key = 'cfield_oitem_' . $item_id;
            $custom_field = get_post_meta($item->get_id(), '_custom_field', true);
            ?>
            <input type="text" name="<?php echo $post_key; ?>" class="form-control" value="<?php echo $custom_field; ?>" >
            <?php
        }
        Copy
    • #220456

      Can you please let us know exactly what flow are you trying to achieve on your end so that we can assist you further.

      • #220457
        l.gan
        Participant
        This reply has been marked as private.
    • #220468

      Hello @l.gan, It looks like you’re trying to implement a custom flow. To be honest, providing a solution for this custom flow exceeds the capabilities of our free support.
      If you want assistance with your custom work, you may reach out to our custom team at custom.dev@multivendorx.com and they will assist you there accordingly.
      However, please let us know exactly where you want to add the custom field, and we can provide you with the appropriate hook or filter to help you add it.
      Thanks for your understanding. .

    • #221558
      steven-6784
      Participant

      Hello,
      I’m also having trouble with saving a custom field. Whilst the code to add the field is supplied by MVx, the code to save it is not.
      Were you able to resolve your issue? If so could you let others know how you resolved it? Thank you!

      • #221559
        l.gan
        Participant

        Hello

        Unfortunately, I was unable to save the field. The problem is still not resolved.
        But I’m glad that this is interesting not only to me. Perhaps the team will have free time and maybe some kind of guide will be there.

    • #221561

      Hello there, Kindly follow the code given here https://multivendorx.com/docs/code-snippet/add-new-tab-in-add-product-page/  for the custom code to add a custom field in the vendor dashboard.

      Now currently we do not have any readymade custom code for saving the custom field. Kindly provide our team some time to get back to you with the code to save the field data. Please note as our team is currently preoccupied with their preassigned work hence it might take us some time to get back to you with the custom code.
      Thanks for your understanding.

      • #221613
        l.gan
        Participant

        Thank you for your help and for coming back to discuss this issue.
        The code you shared adds a custom tab and field to a single product page.

        And we need to add it to the order, to the meta of each product.
        For example, if we sold 3 pairs of boots in an order, then we must add a field to each pair. And the value of this field should be different, because this is a product label. Each product has its own labeling, which can be assigned only after it is understood which product is packaged for shipment.

    • #221619

      Hello @l.gan, Yes, you are absolutely right that the earlier shared code was for adding a custom field on the edit product page in the vendor dashboard. We shared that code in response to queries from other users.

      For your required flow, we do not have any ready-made code available. Implementing your required flow involves substantial coding support, which is beyond our free support capabilities.

      If you need assistance with the required hook/filter, please let us know. Alternatively, you can hire our service team from here: https://multivendorx.com/custom-development/. They will assist you in implementing your required flow.

      Let us know if you need any further assistance from our end.

    • #235251

      It’s been long and we have not heard back from you. We presume your query is resolved now. We are closing this thread. If you need help or face issue in future please do create a new support ticket.

Viewing 8 reply threads

The topic ‘Save custom order item field on Woocommerce admin order pages + Vendor Dashboard’ is closed to new replies.