Добавить столбец для даты заказа и общей суммы заказа в отчет woocommerce csv - PullRequest
0 голосов
/ 21 февраля 2019

При экспорте отчета из WooCommerce я хотел бы указать дату заказа и сумму заказа .

Ниже приведен код, который я использую дляуже включают некоторые другие данные из user_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 голосов
/ 22 февраля 2019
    /**
     * 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);
...