I have searched high and low for this answer. Seems like it should be so easy.
The basic set-up for listing a purchased product's download links in the user account in WooCommerce is:
echo apply_filters( 'woocommerce_available_download_link', '<a href="' . esc_url( $download['download_url'] ) . '">' . $download['download_name'] . '</a>', $download );
This ends up showing like this in the account:
Basically, it lists the products name, followed by the included link. If you have ten links per product to download, then this list gets long.. Then, if you have multiple products purchased, each with ten links, it's just a long run on list. What I'm looking for is a solution to make this list look like this...and notice now where Product 2 starts after Product 1.
I'm totally surprised this option isn't standard, but I can't find any solution. I've tried and tried...so much code that I don't even know where to start.
Anyone have any idea on this WooCommerce issue?
For anyone out there who's looking to group downloadable items return by
WC()->customer->get_downloadable_products()
function by product ID.This following below snippet modify the return data for the function
WC()->customer->get_downloadable_products()
to group downloadable files by product ID.Once the filter is in place, use the filter hook
woocommerce_account_downloads_column_download-file
to modify the layout to list downloadable files in ordered list.One thing to note here, that the data structure of original download files array is unchanged, we have just introduced a new key
list[]
which holds each downloadable file URL and name in thelist
key.