I am trying to manipulate the download URL link for files inside an order.
Basically, I have a use case when a download product is bought I need to add files to the order to be able to download it. So I cannot add an order ID to a product because there is no order at that moment.
Point is, every downloadable product needs to have a dynamic link because it will be generated on the fly .
So how can I add data to the product download URL link ->
WooCommerce offers 2 filters that can be used to achieve what you are looking for:
A) woocommerce_download_product_filepath used to specify what URL contains the file to be downloaded and it takes the following parameters:
And it is registered like this:
add_filter( 'woocommerce_download_product_filepath', 'change_woocommerce_file_download_path', 10, 5 );
More info here https://wp-kama.com/plugin/woocommerce/hook/woocommerce_download_product_filepath
B) woocommerce_file_download_filename used to manipulate the downloaded file's name and it takes the following parameters:
And it is registered like this:
add_filter( 'woocommerce_file_download_filename', 'change_woocommerce_file_download_filename', 10, 2 );
More info here https://wp-kama.com/plugin/woocommerce/hook/woocommerce_file_download_filename