Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Vincent

Adding Fields from an Array

FooEvents plugin is saving custom meta to a WooCommerce order, as a custom field, with an array as the value.

I have used PHP echo to print_r the get_post_meta for the order custom meta key of WooCommerceEventsOrderTickets

The result is below, to give you an idea of the array.

I am looking to add a column for a handful of the fields within this array. Such as WooCommerceEventsAttendeeName, WooCommerceEventsAttendeeLastName, and fooevents_custom_organization

Can you provide any assistance with this? It would maybe be a great use case for your current Extra (Experimental) Columns plugin, since FooEvents is a pretty popular plugin with WooCommerce. It would be great to be able to tweak that file, to output some of the fields from this array.

For now, I’ve added the array itself to the Column (e.g., https://d.pr/free/i/7SEAmJ), but the data doesn’t get exported with the CSV. :(

Array
(
    [1] => Array
        (
            [1] => Array
                (
                    [WooCommerceEventsProductID] => 454
                    [WooCommerceEventsOrderID] => 4609
                    [WooCommerceEventsTicketType] => 
                    [WooCommerceEventsStatus] => Unpaid
                    [WooCommerceEventsCustomerID] => 64
                    [WooCommerceEventsAttendeeName] => AttendeeFirst
                    [WooCommerceEventsAttendeeLastName] => AttendeeLast
                    [WooCommerceEventsAttendeeEmail] => jon@freshysites.com
                    [WooCommerceEventsAttendeeTelephone] => 607-123-4567
                    [WooCommerceEventsAttendeeCompany] => 
                    [WooCommerceEventsAttendeeDesignation] => 
                    [WooCommerceEventsVariations] => Array
                        (
                            [attribute_pa_registration-options] => nassgap-member
                        )

                    [WooCommerceEventsVariationID] => 4078
                    [WooCommerceEventsPrice] => $675.00
                    [WooCommerceEventsPurchaserFirstName] => Jon
                    [WooCommerceEventsPurchaserLastName] => Fuller
                    [WooCommerceEventsPurchaserEmail] => freshyjon@gmail.com
                    [WooCommerceEventsCustomAttendeeFields] => Array
                        (
                            [fooevents_custom_address] => 123 Attendee St
                            [fooevents_custom_city] => Attendee City
                            [fooevents_custom_state/province] => Nevada
                            [fooevents_custom_postal_code] => 13813
                            [fooevents_custom_organization] => Attendee LLC
                            [fooevents_custom_title] => Attendee Title
                        )

                )

        )

)

Any assistance would be appreciated!

3 years, 4 months ago
Stefan
Developer

Hi Vincent,

Since you already get this column working with a flatten array, I suspect you’re using the following filter:

ac/column/value

If you’re happy with the value as it is now, you can use the following filter for the export value.

acp/export/value

Even better would be to create your own column (or more) by following our documentation. You could create your own setting that gives you a drop-down of all available properties that you can display. Creating a setting is not documented in the toolkit, but if you’re a developer, you can have a look at your custom field setting to get the idea.

And instead of using the custom field, I’m sure there are some FooEvents methods that you can use to retrieve the values for a post which probably makes it somewhat easier to access the data.

Unfortunately I cannot help you with a ready-to-use column in the Experimental Column plugin, but I can review your column or help you further if you get stuck during developing the column.

3 years, 4 months ago
Vincent

Does it matter if we use

if ( $column instanceof AC_Column_CustomField )

or

if ( $column instanceof ACP_Column_CustomField )

We currently are utilizing the Pro version of the plugin.

3 years, 4 months ago
Stefan
Developer

It doen’t matter.
ACP_Column_CustomField Extends from AC_Column_CustomField so both should work.
But if you don’t use any pro features in your filter, you can use the free version (AC_Column_CustomField) so your filter will also work when you only want to use it in the free version.

3 years, 4 months ago
Vincent

I’ve been able to essentially replace the “Array” value (https://d.pr/free/i/7SEAmJ) with new data, by essentially overriding the $value of that initial custom field.

However, the issue is that I need to create numerous new columns to be able to output certain fields within that array. Does this mean I’d need to create multiple plugins, by using your Starter Kit? Or is there a way to create multiple columns within the single Starter Kit?

Basically, I just need to output the values of some of the fields within the array… where each value would be its own column.

Currently, I am replacing the column value and getting it to look like this: https://d.pr/free/i/jKjAsI

I accomplished this via: https://gist.github.com/Garconis/720099596f3ba6f086d83864920fca15

But since this data is also going to be exported, I should probably instead be showing each of those fields (Organization, Title, etc.) as their own columns on the Order Screen. I had previously planned on just adding some additional useless columns within the Admin Columns settings for Orders… and then replace those useless columns with data/values from the WooCommerceEventsOrderTickets array.

So essentially, I’d be overwriting the values with new values. Obviously this may not be ideal, but I also didn’t want to have to maintain numerous plugins for each custom column, if I were to create the columns from scratch with your Starter Kit.

3 years, 4 months ago
Stefan
Developer

Please notice that the toolkit is just meant as an example. But please let me explain to you what you can do with it.

1) You don’t need a plugin for each new column your create. You can create multiple columns in different files and just register them in the ac/column_types hook with $list_screen->register_column_type method. You can load as my columns as you like in that hook.

2) You can even create one column where you can select which field you want to display. But in this case you’ll need to create your own setting and like I said in my previous comment, we don’t have much documentation about this. Of course, creating one column that can handle all the different fields would be ideal but this is a bit more complex. You could have a look at the following (relatively simple) setting AC_Settings_Column_AttachmentDisplay.

Using the filter is not very scalable since you check for a column instance and the custom field key, so in this case you could only use the filter for the specific custom field once.

3 years, 4 months ago
Vincent

I’ve ran the update for Admin Columns Pro, and also the Admin Columns Experimental Columns plugin from Github. However, now it’s causing my 2 custom columns to no longer work. I was previously overriding the data of a custom field, with new info. But now that new info is not showing anymore.

3 years, 1 month ago
Stefan
Developer

Please notice that in the latest version we changed all our classes to namespaced classes.
The column check must be written like this now:

if ( $column instanceof AC\Column\CustomField ) {
if ( $column instanceof ACP\Column\CustomField ) {

When you change your code to this, it should work.

3 years, 1 month ago
Vincent

Phew! You had me worried. Works like a charm!

3 years, 1 month ago

You must be logged in to reply to this topic.