Home > other >  Woocommerce -> Get Title Product Order
Woocommerce -> Get Title Product Order

Time:10-20

I would like to download the purchased product names as you can see in the Admin panel, the Orders tab. I am trying different ways, does anyone have any suggestions?

<?php
/**
 * @snippet       Add Column to Orders Table (e.g. Product) - WooCommerce
 */
 
add_filter( 'manage_edit-shop_order_columns', 'inforder_add_new_order_admin_list_column' );
 
function inforder_add_new_order_admin_list_column( $columns ) {
    $columns['product_order'] = 'Product';
    return $columns;
}

add_action( 'manage_shop_order_posts_custom_column', 'inforder_add_new_order_admin_list_column_content' );
 
function inforder_add_new_order_admin_list_column_content( $column ) {
   
    global $post;
 
    if ( 'product_order' === $column ) {
 
        $order = wc_get_order( $post->ID );
        echo $order->get_currency();
      
    }
}
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

Now this is an example of a currency, I have no problem with that.

CodePudding user response:

This is probably what you want for displaying products of order:

 /**
 * @snippet       Add Column to Orders Table (e.g. Product) - WooCommerce
 */

add_filter( 'manage_edit-shop_order_columns', 'inforder_add_new_order_admin_list_column' );

function inforder_add_new_order_admin_list_column( $columns ) {
    $columns['product_order'] = 'Product';
    return $columns;
}

add_action( 'manage_shop_order_posts_custom_column', 'inforder_add_new_order_admin_list_column_content' );

function inforder_add_new_order_admin_list_column_content( $column ) {

    global $post;

    if ( 'product_order' === $column ) {

        $order = wc_get_order( $post->ID );
        $items = $order->get_items();
        $count = count($items);
        $i = 1;
        foreach($items as $item) {
            if($i==$count) 
                echo $item->get_name();
            else
                echo $item->get_name() .', ';
            $i  ;
        }
    }
}
  • Related