• Resolved jurasjo

    (@jurasjo)


    Hi
    Maybe someone has a code for adding column in orders page which will show payment date instead of date of placing an order.

    SCREEN

    Manual payment via bank transfer is often +few days and I would like to have that info as a column next to default date.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jurasjo

    (@jurasjo)

    I have made this code:

    // Adding the date for column
    function custom_shop_order_column($columns) {
      $columns['payment_date'] = __('P?atno??', 'kursysklepbs');
        return $columns;
    }
    add_filter('manage_edit-shop_order_columns', 'custom_shop_order_column', 11);
    
    // Adding data for column
    function custom_orders_list_column_content( $column ) {
      global $post, $woocommerce, $the_order;
        $order_id = $the_order->get_id();
      switch ( $column )
        {
          case 'payment_date' :
            $myVarOne = get_post_meta( $order_id, '_completed_date', true );
    				echo substr($myVarOne, 0, -9);
            	break;
        }
    }
    add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 10, 2 );
    

    The only thing left is I would like this column to bee sortable.

    Thread Starter jurasjo

    (@jurasjo)

    Finally my working code looks like:

    // Adding column P?atno??
    function custom_shop_order_column($defaults) {
      $defaults['payments'] = __('Payment', 'kursymemobs');
        return $defaults;
    }
    add_filter('manage_edit-shop_order_columns', 'custom_shop_order_column', 11 );
    
    // Adding data for column P?atno??
    function custom_orders_list_column_content( $column ) {
      global $post, $woocommerce, $the_order;
        $order_id = $the_order->get_id();
      switch ( $column )
        {
          case 'payments' :
            $myVarOne = get_post_meta( $order_id, '_completed_date', true );
    				echo substr($myVarOne, 0, -9);
            	break;
        }
    }
    add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 10, 2 );
    
    //Make column P?atno?? sortable
    function my_sortable_column( $columns ) {
        $columns['payments'] = 'modified';
        	return $columns;
    }
    add_filter( 'manage_edit-shop_order_sortable_columns', 'my_sortable_column' );

    It works quite well.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Payment date column’ is closed to new replies.