M
M
makboriska2022-01-10 19:12:24
WordPress
makboriska, 2022-01-10 19:12:24

How to show purchased items in Woocommerce?

There is an online store where keys are sold (they come via api) and you need to make sure that in the order history there is a history of purchased GOODS, not orders, i.e. by default, wc shows us orders in which there can be 5 products, for example, how to make these 5 products be displayed instead of orders?

I decided to do it by deleting / adding columns to the order history

add_filter( 'woocommerce_my_account_my_orders_columns', 'additional_my_account_orders_column', 10, 3 );
function additional_my_account_orders_column( $columns ) {
    $new_columns = [];

    foreach ( $columns as $key => $name ) {
        $new_columns[ $key ] = $name;

        if ( 'order-status' === $key ) {
            $new_columns['order-items'] = __( 'Voucher', 'woocommerce' );
        }
    }
    return $new_columns;
}

add_action( 'woocommerce_my_account_my_orders_column_order-items', 'additional_my_account_orders_column_content', 10, 3 );
function additional_my_account_orders_column_content( $order ) {
    $details = array();

    foreach( $order->get_items() as $item )
        $details[] = $item->get_name();

    echo count( $details ) > 0 ? implode( '<br>', $details ) : '&ndash;';
}

Thus, I pulled out the name of the goods that are stored in the order, but how to split them, are they now in one line?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WP Panda, 2022-01-10
@wppanda5

well, don't do Implode - it won't be a string, but an array

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question