WooCommerce订单和WooCommerce自定义字段插件以及活动门票加

时间:2017-08-22 07:10:39

标签: php excel wordpress woocommerce custom-fields

我正在尝试将Woocommerce Custom Fields插件中的数据添加到通过Tribe的Events Tickets Plus插件导出的Excel电子表格中。

到目前为止,使用以下代码,我已设法在电子表格中添加列,不仅会将名字和姓氏列添加到电子表格中,还会从订单中提取列的值。
我还设法添加了relationship_to_child和emergency_medical的列,但是,当我们从rightpress插件添加数据时,我感到困惑。我尝试在自定义字段的开头添加“get”但这不起作用。

根据权利,Checkout字段如下:

                               |    Meta Value         |    Location
— — — — — — — — — — — — — — — —|— — — — — — — — — — — —|— — — — — — — — — — — — — — — — — — 
                               |                       |
    _wccf_cf_{key}             |    field value        |    in order meta
                               |                       |
    _wccf_cf_id_{key}          |    field id           |    in order meta
                               |                       |
    _wccf_cf_data_{key}        |    extra data array   |    in order meta
                               |                       |
    _wccf_file_{access_key}    |    file data          |    in order meta
                               |                       |

以下是代码

add_action( 'tribe_events_tickets_generate_filtered_attendees_list', 'tribe_export_custom_set_up' );
function tribe_export_custom_set_up ( $event_id ) {
    //Add Handler for Community Tickets to Prevent Notices in Exports

    if ( ! is_admin() ) {
        $screen_base = 'tribe_events_page_tickets-attendees';

    } else {
        $screen      = get_current_screen();
        $screen_base = $screen->base;
    }
    $filter_name = "manage_{$screen_base}_columns";

    add_filter( $filter_name, 'tribe_export_custom_add_columns', 100, 1 );
    add_filter( 'tribe_events_tickets_attendees_table_column', 'tribe_export_custom_populate_columns', 10, 3 );
}

function tribe_export_custom_add_columns ( $columns ) {
    $columns['wc_first_name'] = 'First Name';
    $columns['wc_last_name'] = 'Last Name';
    $columns['wc_emergency_medical'] = 'Consent Emergency Medical'; // array key changed
    $columns['wc_relationship_to_child'] = 'Relationship to Child'; // array key changed
    $columns['wc_consent_marketing'] = 'Consent to Marketing'; // array key changed

    return $columns;
}



function tribe_export_custom_populate_columns ( $value, $item, $column ){

    $order_id = $item["order_id"]; // tested and works

    $firstname = get_post_meta( $order_id, '_billing_first_name', true );
    $lastname = get_post_meta( $order_id, '_billing_last_name', true );
    $emergencymedical = get_post_meta( $order_id, '_wccf_cf_emergency_medical', true );
    $relationshiptochild = get_post_meta( $order_id, '_wccf_cf_relationship_to_child', true );
    $consentmarketing = get_post_meta( $order_id, '_wccf_cf_consent_marketing', true );


    if ( ! empty( $order_id ) || $order_id > 0 )
    {
        if ( $column == 'wc_first_name') {
            $value = $firstname;
        } elseif ( $column == 'wc_last_name') {
            $value = $lastname;
        } elseif ( $column == 'wc_emergency_medical') {
            $value = $emergencymedical;
        } elseif ( $column == 'wc_relationship_to_child') {
            $value = $relationshiptochild;
        } elseif ( $column == 'wc_consent_marketing') {
            $value = $consentmarketing;
        }
    } else {
        if ( $column == 'wc_first_name') {
            $value = 'test 1';
        } elseif ( $column == 'wc_last_name') {
            $value = 'test 2';
        } elseif ( $column == 'wc_emergency_medical') {
            $value = 'test 3';
        } elseif ( $column == 'wc_relationship_to_child') {
            $value = 'test 4';
        } elseif ( $column == 'wc_consent_marketing') {
            $value = 'test 5';
        }
    }
    if (is_array($value)) $value = join(', ', $value);
    return $value;
}

有人能帮助我吗?

0 个答案:

没有答案