Ecommerce Shopify WordPress Discussion

Changing the all filename field of WooCommerce products

I have many plugins that use filename field of the file of my WooCommerce downloadable product, to show the download button! WooCommerce also does this here to display the file name in the user panel: woocommerce/templates/order/order-downloads.php with: echo '<a href="' . esc_url( $download['download_url'] ) . '" class="woocommerce-MyAccount-downloads-file button alt">' . esc_html( $download['download_name'] ) . '</a>'; I don't want to edit the filename field of all the products I also don't want to edit the codes of those plugins Is there a way to symbolically and hypothetically change and set all filename? i think WooCommerce should to introduce the file name as I choose. For example, tell everyone file name of all file is "free download", not "ps-action.zip" i think woocommerce create and handle this here: 1-woocommerce/includes/class-wc-download-handler.php 2-woocommerce/src/Admin/API/Reports/Downloads/Controller.php 1-class-wc-download-handler.php line 218: public static function download( $file_path, $product_id ) { if ( ! $file_path ) { self::download_error( __( 'No file defined', 'woocommerce' ) ); } $filename = basename( $file_path ); if ( strstr( $filename, '?' ) ) { $filename = current( explode( '?', $filename ) ); } $filename = apply_filters( 'woocommerce_file_download_filename', $filename, $product_id ); 2-Controller.php line 84: // Figure out file name. // Matches https://github.com/woocommerce/woocommerce/blob/4be0018c092e617c5d2b8c46b800eb71ece9ddef/includes/class-wc-download-handler.php#L197. $product_id = intval( $data['product_id'] ); $_product = wc_get_product( $product_id ); // Make sure the product hasn't been deleted. if ( $_product ) { $file_path = $_product->get_file_download_path( $data['download_id'] ); $filename = basename( $file_path ); $response->data['file_name'] = apply_filters( 'woocommerce_file_download_filename', $filename, $product_id ); $response->data['file_path'] = $file_path; } else { $response->data['file_name'] = ''; $response->data['file_path'] = ''; } Maybe we can apply a filter in this way to display our text (just display it, not insert it into the filename field) Im beginner, thank you for helping me Update: I found this, maybe this is what is needed: woocommerce/includes/wc-user-functions.php line 656 // Download name will be 'Product Name' for products with a single downloadable file, and 'Product Name - File X' for products with multiple files. $download_name = apply_filters( 'woocommerce_downloadable_product_name', $download_file['name'], $_product, $result->download_id, $file_number ); $downloads[] = array( 'download_url' => add_query_arg( array( 'download_file' => $product_id, 'order' => $result->order_key, 'email' => rawurlencode( $result->user_email ), 'key' => $result->download_id, ), home_url( '/' ) ), 'download_id' => $result->download_id, 'product_id' => $_product->get_id(), 'product_name' => $_product->get_name(), 'product_url' => $_product->is_visible() ? $_product->get_permalink() : '', // Since 3.3.0. 'download_name' => $download_name, 'order_id' => $order->get_id(), 'order_key' => $order->get_order_key(), 'downloads_remaining' => $result->downloads_remaining, 'access_expires' => $result->access_expires, 'file' => array( 'name' => $download_file->get_name(), 'file' => $download_file->get_file(), ), ); $file_number++; } } return apply_filters( 'woocommerce_customer_available_downloads', $downloads, $customer_id ); } And here in the code of the user panel, there is a variable called $download that seems to get the name from there, this name is so generic and repeated that I can't find its original location: echo '<a href="' . esc_url( $download['download_url'] ) . '" class="woocommerce-MyAccount-downloads-file button alt">' . esc_html( $download['download_name'] ) . '</a>'
You can use the woocommerce_file_download_filename filter to change the displayed file name without actually modifying the product's filename field. This filter is applied to the file name before it's displayed, so it won't change the actual file on your server. Here's an example of how you can use this filter to display a custom text instead of the actual filename: PHP CODE: add_filter('woocommerce_file_download_filename', 'custom_download_filename', 10, 2); function custom_download_filename($filename, $product_id) { // You can replace "free download" with any text you want. return 'free download'; } Add this to theme's functions.php file. This will change the displayed file name to "free download" for all downloadable products. Please note that this only affects the display, not the actual file name on your server or in your WooCommerce database. It's a visual change for users and won't impact the functionality of the downloads.

February 26, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.