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';
}
}
>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.