wpgenie

show products in order column in Orders for WooCommerce

Oct 2nd, 2020 (edited)
2,754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2.  
  3. /* visit us - https://wpgenie.org */
  4.  
  5.  
  6. if ( is_admin() ) {
  7.  
  8.     add_filter( 'manage_edit-shop_order_columns', 'wpgenie_show_product_order', 15 );
  9.  
  10.     function wpgenie_show_product_order($columns){
  11.        //add column
  12.        $columns['product-display'] = __( 'Products in Order');
  13.        return $columns;
  14.     }
  15.  
  16.     add_action( 'manage_shop_order_posts_custom_column' , 'wpgenie_custom_shop_order_column', 10, 2 );
  17.  
  18.     function wpgenie_custom_shop_order_column( $column ) {
  19.  
  20.         global $post, $woocommerce, $the_order;
  21.    
  22.         switch ( $column ) {
  23.  
  24.             case 'product-display' :
  25.                
  26.                 $terms = $the_order->get_items();
  27.  
  28.                 if ( is_array( $terms ) ) {
  29.                     foreach($terms as $term){
  30.                         $product = wc_get_product( $term['product_id'] );
  31.                         if ( is_object($product) && !(get_post_status( $term['product_id'] ) == "trash")  ) {
  32.                             echo $term->get_quantity() .' x <a href="'.$product->get_permalink().'" target="_blank">' . $term['name'] .'</a><br>';
  33.                         } else {
  34.                             echo $term->get_quantity() .' x ' . $term['name'] .' (in trash or deleted) <br>';
  35.                         }
  36.                     }
  37.                     } else {
  38.                     _e( 'Unable get the products', 'woocommerce' );
  39.             }
  40.                 break;
  41.         }
  42.  
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment