WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Add product as column in orders overview (5 posts)

  1. Yasp0
    Member
    Posted 1 year ago #

    In the Woocommerce orders overview I want to add a column which shows the product name(s).

    First I added an extra column to the custom post 'shop_order'.

    add_filter('manage_edit-shop_order_columns', 'extra_column');
    	function extra_column($columns) {
    		$columns['title'] = 'Product';
    		return $columns;
    	}

    Working fine...but it needs to show the title from the custom post 'product'.

    Anyone?

    http://wordpress.org/extend/plugins/woocommerce/

  2. IgniteWoo
    Member
    Posted 1 year ago #

    You probably need another filter. Possibly like this:

    add_action( 'manage_shop_order_posts_custom_column', 'my_custom_order_columns', 2 );
    
    function my_custom_order_columns( $column ) {
    	switch ( $column ) {
    		case "title" :
    // code to look up product title goes here
    // echo get_the_title( $PRODUCT_ID_GOES_HERE );
    
    		break;
    }
  3. chiseledimages
    Member
    Posted 11 months ago #

    yspo0, did you get this to work?

  4. Yasp0
    Member
    Posted 11 months ago #

    Yes, a friend of mine wrote a plugin. This should do it:

    add_filter( 'manage_edit-shop_order_columns', 'imarcon_set_custom_column_order_columns');
    
    function imarcon_set_custom_column_order_columns($columns) {
    // global $woocommerce;
    $nieuwearray = array();
     foreach($columns as $key => $title) {
       if ($key=='billing_address') // in front of the Billing column
         $nieuwearray['order_producten']  = __( 'Products', 'woocommerce' );
        $nieuwearray[$key] = $title;
      }
        return $nieuwearray ;
    }
    
    add_action( 'manage_shop_order_posts_custom_column' , 'imarcon_custom_shop_order_column', 10, 2 );
    function imarcon_custom_shop_order_column( $column ) {
     global $post, $woocommerce, $the_order;
    
        switch ( $column ) {
    
            case 'order_producten' :
                $terms = $the_order->get_items();
    
    	      if ( is_array( $terms ) ) {
                 	foreach($terms as $term)
    		{
    		echo $term['item_meta']['_qty'][0] .' x ' . $term['name'] .'<br />';
    		}
                  } else {
                  	_e( 'Unable get the producten', 'woocommerce' );
    		}
                break;
    
        }
    }

    It returns e.g. : 2 x productname

  5. chiseledimages
    Member
    Posted 11 months ago #

    thanks, and thank you for the quick response!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.