• Resolved zihniates

    (@zihniates)


    Hey there. Thanks for great plugin.
    I need ti add a column to the Woocommerce Orders page.

    add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 20, 2 );
    function custom_orders_list_column_content( $column, $post_id )
    {
        switch ( $column )
        {
            case 'my-column1' :
                // Get custom post meta data
                $my_var_one = do_shortcode('[wcpdf_download_invoice]');
                if(!empty($my_var_one))
                    echo $my_var_one;
    
                else
                    echo '<small>(<em>TEST</em>)</small>';
    
                break;
    
        }
    }

    Here is my code and it is not working at all. Can you help me?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Darren Peyou

    (@dpeyou)

    @zihniates,

    The code to add a column would include a little more.
    https://stackoverflow.com/questions/36446617/add-columns-to-admin-orders-list-in-woocommerce

    I see that you are trying to use the shortcode however: why not use the action buttons instead?
    To activate them, you’d need to select “Screen Options” in the top right corner of your Orders page:

    screen-Options

    Then select actions:

    screen-Options-Actions

    • This reply was modified 3 years, 6 months ago by Darren Peyou. Reason: adding link
    Thread Starter zihniates

    (@zihniates)

    I have no idea about that. And yes, that is what i need. Thank you.

    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hello @zihniates,

    As I prefer to use the action buttons that my colleague @dpeyou mentioned, it’s possible to create a Download invoice column/button if you need it, adding the following code snippet to your site:

    /**
     * Add a "Download invoice" column/button in the order list
     */
    add_filter( 'manage_edit-shop_order_columns', 'wpo_wcpdf_invoice_date_column', 9999 );
    function wpo_wcpdf_invoice_date_column( $columns ) {
    	$insert_after = 'pdf_invoice_number';
    	$position = array_search( $insert_after, array_keys( $columns ) ) + 1;
    	// put the column after the Status/Invoice number column
    	return array_slice( $columns, 0, $position, true )
    	+ array( 'pdf_download_invoice' => __( 'Download invoice', 'woocommerce-pdf-invoices-packing-slips' ) )
    	+ array_slice( $columns, $position, null, true ) ;
    }
    add_action( 'manage_shop_order_posts_custom_column', 'wpo_wcpdf_invoice_date_column_data', 10, 2 );
    function wpo_wcpdf_invoice_date_column_data( $column, $post_id ) {
    	if ( $column == 'pdf_download_invoice' && $order = wc_get_order( $post_id ) ) {
    		if($invoice = wcpdf_get_invoice ($post_id)) {
    			//print_r($invoice);
    			echo '<a href="' . wp_nonce_url( admin_url( "admin-ajax.php?action=generate_wpo_wcpdf&document_type=invoice&order_ids=" . $post_id ), 'generate_wpo_wcpdf' ). '" class="button" target="_blank">Download invoice</a>';			
    		} else {
    			echo 'The order is not yet ready to create an invoice.';
    		}
    	}
    }

    If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add Column To WooCommerce Orders Page’ is closed to new replies.