在woocommerce报告csv中添加订单日期和订单总数列

时间:2019-02-21 20:59:17

标签: csv woocommerce export report

从WooCommerce导出报告时,我想包括订单日期订单总数

下面是我用来包含来自user_id的其他数据的代码。但是我还需要包含来自order_id的数据。

如果有人能告诉我该怎么做,我将不胜感激!

谢谢!

/**
 * Modify the member CSV Export column headers.
 *
 * @param string[] $headers array of column headers as 'key' => 'output_name'
 * @return string[] updated headers
 */
function sv_wc_memberships_modify_member_export_headers( $headers ) {

    // add a column header for "member phone"
    foreach ( $headers as $key => $name ) {

        $new_headers[ $key ] = $name;

        // add our new header after the member email
        if ( 'member_email' == $key ) {
            $new_headers['member_company_name'] = 'member_company_name';
            $new_headers['member_address_1'] = 'member_address_1';
            $new_headers['member_address_2'] = 'member_address_2';
            $new_headers['member_suburb'] = 'member_suburb';
            $new_headers['member_state'] = 'member_state';
            $new_headers['member_postcode'] = 'member_postcode';
            $new_headers['member_phone'] = 'member_phone';
        }
    }
    return $new_headers;
}



add_filter( 'wc_memberships_csv_export_user_memberships_headers', 'sv_wc_memberships_modify_member_export_headers' );
/**
 * Adds data for our new member export column.
 *
 * Note that no column name check is needed since the filter name is scoped to the column key.
 *
 * @param string[] $data export data as 'column' => 'data'
 * @param string $_ unused, the column key
 * @param \WC_Memberships_User_Membership $user_membership User Membership object
 * @return string[] updated data
 */

function sv_wc_memberships_modify_member_export_columns_a( $data, $_, $user_membership ) {

    // return the data for this column
    return get_user_meta( $user_membership->get_user_id(), 'billing_company', true );
}
add_filter( 'wc_memberships_csv_export_user_memberships_member_company_name_column', 'sv_wc_memberships_modify_member_export_columns_a', 10, 3 );


function sv_wc_memberships_modify_member_export_columns_b( $data, $_, $user_membership ) {

    // return the data for this column
    return get_user_meta( $user_membership->get_user_id(), 'billing_address_1', true );
}
add_filter( 'wc_memberships_csv_export_user_memberships_member_address_1_column', 'sv_wc_memberships_modify_member_export_columns_b', 10, 3 );

function sv_wc_memberships_modify_member_export_columns_c( $data, $_, $user_membership ) {

    // return the data for this column
    return get_user_meta( $user_membership->get_user_id(), 'billing_address_2', true );
}
add_filter( 'wc_memberships_csv_export_user_memberships_member_address_2_column', 'sv_wc_memberships_modify_member_export_columns_c', 10, 3 );

function sv_wc_memberships_modify_member_export_columns_d( $data, $_, $user_membership ) {

    // return the data for this column
    return get_user_meta( $user_membership->get_user_id(), 'billing_city', true );
}
add_filter( 'wc_memberships_csv_export_user_memberships_member_suburb_column', 'sv_wc_memberships_modify_member_export_columns_d', 10, 3 );

function sv_wc_memberships_modify_member_export_columns_e( $data, $_, $user_membership ) {

    // return the data for this column
    return get_user_meta( $user_membership->get_user_id(), 'billing_state', true );
}
add_filter( 'wc_memberships_csv_export_user_memberships_member_state_column', 'sv_wc_memberships_modify_member_export_columns_e', 10, 3 );

function sv_wc_memberships_modify_member_export_columns_f( $data, $_, $user_membership ) {

    // return the data for this column
    return get_user_meta( $user_membership->get_user_id(), 'billing_postcode', true );
}
add_filter( 'wc_memberships_csv_export_user_memberships_member_postcode_column', 'sv_wc_memberships_modify_member_export_columns_f', 10, 3 );

function sv_wc_memberships_modify_member_export_columns_g( $data, $_, $user_membership ) {

    // return the data for this column
    return get_user_meta( $user_membership->get_user_id(), 'billing_phone', true );
}
add_filter( 'wc_memberships_csv_export_user_memberships_member_phone_column', 'sv_wc_memberships_modify_member_export_columns_g', 10, 3 );

1 个答案:

答案 0 :(得分:0)

    /**
     * Modify the member CSV Export column headers.
     *
     * @param string[] $headers array of column headers as 'key' => 'output_name'
     * @return string[] updated headers
     */
    function sv_wc_memberships_modify_member_export_headers($headers) {

        // add a column header for "member phone"
        foreach ($headers as $key => $name) {

            $new_headers[$key] = $name;

            // add our new header after the member email
            if ('member_email' == $key) {
                $new_headers['member_company_name'] = 'member_company_name';
                $new_headers['member_address_1'] = 'member_address_1';
                $new_headers['member_address_2'] = 'member_address_2';
                $new_headers['member_suburb'] = 'member_suburb';
                $new_headers['member_state'] = 'member_state';
                $new_headers['member_postcode'] = 'member_postcode';
                $new_headers['member_phone'] = 'member_phone';
                $new_headers['order_date'] = 'order_date';
                $new_headers['order_total'] = 'order_total';
            }
        }
        return $new_headers;
    }

    add_filter('wc_memberships_csv_export_user_memberships_headers', 'sv_wc_memberships_modify_member_export_headers');

    /**
     * Adds data for our new member export column.
     *
     * Note that no column name check is needed since the filter name is scoped to the column key.
     *
     * @param string[] $data export data as 'column' => 'data'
     * @param string $_ unused, the column key
     * @param \WC_Memberships_User_Membership $user_membership User Membership object
     * @return string[] updated data
     */
    function sv_wc_memberships_modify_member_export_columns_a($data, $_, $user_membership) {

        // return the data for this column
        return get_user_meta($user_membership->get_user_id(), 'billing_company', true);
    }

    add_filter('wc_memberships_csv_export_user_memberships_member_company_name_column', 'sv_wc_memberships_modify_member_export_columns_a', 10, 3);

    function sv_wc_memberships_modify_member_export_columns_b($data, $_, $user_membership) {

        // return the data for this column
        return get_user_meta($user_membership->get_user_id(), 'billing_address_1', true);
    }

    add_filter('wc_memberships_csv_export_user_memberships_member_address_1_column', 'sv_wc_memberships_modify_member_export_columns_b', 10, 3);

    function sv_wc_memberships_modify_member_export_columns_c($data, $_, $user_membership) {

        // return the data for this column
        return get_user_meta($user_membership->get_user_id(), 'billing_address_2', true);
    }

    add_filter('wc_memberships_csv_export_user_memberships_member_address_2_column', 'sv_wc_memberships_modify_member_export_columns_c', 10, 3);

    function sv_wc_memberships_modify_member_export_columns_d($data, $_, $user_membership) {

        // return the data for this column
        return get_user_meta($user_membership->get_user_id(), 'billing_city', true);
    }

    add_filter('wc_memberships_csv_export_user_memberships_member_suburb_column', 'sv_wc_memberships_modify_member_export_columns_d', 10, 3);

    function sv_wc_memberships_modify_member_export_columns_e($data, $_, $user_membership) {

        // return the data for this column
        return get_user_meta($user_membership->get_user_id(), 'billing_state', true);
    }

    add_filter('wc_memberships_csv_export_user_memberships_member_state_column', 'sv_wc_memberships_modify_member_export_columns_e', 10, 3);

    function sv_wc_memberships_modify_member_export_columns_f($data, $_, $user_membership) {

        // return the data for this column
        return get_user_meta($user_membership->get_user_id(), 'billing_postcode', true);
    }

    add_filter('wc_memberships_csv_export_user_memberships_member_postcode_column', 'sv_wc_memberships_modify_member_export_columns_f', 10, 3);

    function sv_wc_memberships_modify_member_export_columns_g($data, $_, $user_membership) {

        // return the data for this column
        return get_user_meta($user_membership->get_user_id(), 'billing_phone', true);
    }

    add_filter('wc_memberships_csv_export_user_memberships_member_phone_column', 'sv_wc_memberships_modify_member_export_columns_g', 10, 3);




function sv_wc_memberships_modify_member_export_columns_orderdate($data, $_, $user_membership) {
        $order_id = $user_membership->get_order_id();
        $order = wc_get_order($order_id);

    // Get the order ID
        $order_date = $order->get_date_completed();
        return $order_date;
    }

    add_filter('wc_memberships_csv_export_user_memberships_member_order_date', 'sv_wc_memberships_modify_member_export_columns_orderdate', 10, 3);

    function sv_wc_memberships_modify_member_export_columns_ordertotal($data, $_, $user_membership) {

        // return the data for this column
        return get_user_meta($user_membership->get_user_id(), 'billing_phone', true);

        $order_id = $user_membership->get_order_id();
        $order_total = get_post_meta($order_id, '_order_total', true);

        // return the data for this column
        return $order_total;
    }

    add_filter('wc_memberships_csv_export_user_memberships_member_order_total', 'sv_wc_memberships_modify_member_export_columns_ordetotal', 10, 3);