Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Display the attachment in the new column by ACF

I have created an attachment filed by using ACF. Also, I want to show this field as a new column on order table in their woocommerce panel and if this field gets value user can download the value.But in this code I have problem by downlodable link button and it does not working.
Any help is appreciated.

My code so far:

add_filter( 'woocommerce_my_account_my_orders_columns', 'add_attachments_column' );
function add_attachments_column( $columns ) {
    $columns['attachments'] = 'translated files';
    return $columns;
}
//Display the attachment in the new column and enable download
add_action( 'woocommerce_my_account_my_orders_column_attachments', 'display_order_attachments', 10, 1 );
function display_order_attachments( $order ) {
    $attachment_id = get_field( 'translate_field', $order->get_id() );
    if ( $attachment_id ) {
        $attachment_url = wp_get_attachment_url( $attachment_id );
    } else {
        echo 'No translated file';
    }
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The following revisited code will add a custom column and will display the custom column by a downloadable button on customer order list.

/* Display the attachment in the new column and enable download */

// Add a new column to the My Account > Orders table
add_filter( 'woocommerce_my_account_my_orders_columns', 'add_attachments_column' );
function add_attachments_column( $columns ) {
    $columns['attachments'] = 'translated files';
    return $columns;
}
//Display the attachment in the new column and enable download
add_action( 'woocommerce_my_account_my_orders_column_attachments', 'display_order_attachments', 10, 1 );
function display_order_attachments( $order ) {
    $attachment_id = get_field( 'translate_field', $order->get_id() );
    if ( $attachment_id ) {
        $attachment_url = wp_get_attachment_url( $attachment_id );
        echo '<a href="' . $attachment_url . '" target="_blank" download>Download translated File</a>';
    } else {
        echo 'No translated File';
    }
}

Code goes in function.php file of your active child theme (active theme). tested and works.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading