Skip Navigation

[Resolved] Add custom field to woocommerce order items

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

This topic contains 1 reply, has 2 voices.

Last updated by Beda 6 years, 9 months ago.

Author
Posts
#630138

not sure if this is possible. On my site we use woocommerce which has the post type of "orders". The orders table contains details of the items in the order.

On our store orders can be made up of a few items, so when we send the order to the warehouse to pick the items it would be great if, on the orders page, next to each item in the order there was a checkbox "item picked"

i can add post field groups to orders post type, but, that just places a group of fields on the orders page, but, not related to the items in the order.

as i said, dont think this is possible but thought i would ask (as order post type is not created by toolset)

thanks
j

#630266
Screen Shot 2017-05-17 at 10.29.28.png

i can add post field groups to orders post type, but, that just places a group of fields on the orders page, but, not related to the items in the order

Exactly, this is how Custom Fields behave generally in WordPress.

You will need to add options on your own to the fields.
This can be done manually by populating the fields in Toolset > Custom Fields, or, it can be done with the API wpt_field_options().
But this is an unofficial API that is not documented and we cannot assist it.

The filter wpt_field_options can be used to manipulate the options of select and radio field.

Arguments:
- $current_options
- $title (the title of the field)

Output: Array

Required format:

array(
    array(
        '#title' => 'First Title',
        '#value' => 'first-value'
    ),
    array(
        '#title' => 'Second Title',
        '#value' => 'second-value'
    ),
)

Example of usage:
Let's assume your theme has a colorset of dark, light and accent color, which are editable in the theme options. The theme stores these values as a wp_option theme_name_colorset in this format:

array(
    'Dark'         => '#333333',
    'Light'        => '#eeeeee',
    'Accent Color' => '#ff3300'
)  

You want to use these colors on a custom select field to define the headline color of the post. So we create a post field group with a select field: See Screenshot

Now we adding this function to our themes functions.php:

add_filter( 'wpt_field_options', function ( $current_options, $title_of_field ) {
    if ( $title_of_field != 'Headline Color' ) {
        // not our "Headline Color" field
        return $current_options;
    }

    $theme_colorset = get_option( 'theme_name_colorset' );

    if ( ! $theme_colorset ) {
        // no theme colors are set yet
        return array(
            array(
                '#title' => 'No colors available',
                '#value' => 0
            )
        );
    }

    $new_options = array();
    foreach ( $theme_colorset as $color_title => $color_value ) {
        $new_options[] = array(
            '#title' => $color_title . ' (' . $color_value . ')',
            '#value' => $color_value
        );
    }

    return $new_options;
}, 10, 2 );

As said we cannot assist this and it's not documented, maybe if you require more help with this you can find assistance by the contractors:
https://toolset.com/contractors/

The forum ‘Types Community Support’ is closed to new topics and replies.