WooCommerce重命名数字下载文件 [英] WooCommerce renaming a digital download file
本文介绍了WooCommerce重命名数字下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在使用WooCommerce销售一些数字产品。我已经设置了以下设置"为安全起见,将唯一的字符串附加到文件名中",我想知道是否有办法在客户下载文件时将其重命名回其原始名称。
例如,文件名为product-9j978f.zip,当客户下载时,它将重命名为duct.zip。
谢谢您,如有任何帮助,我们将不胜感激
推荐答案
代码如下
/**
* Change the downloadable file name
*
* @param string $filename Downloadable file name.
* @param int $product_id WC product id.
* @return string
*/
function change_woocommerce_file_download_filename( $filename, $product_id ) {
// Get the file extension from the processed file name.
$filetype = wp_check_filetype( $filename );
// You can generate a new file using Product ID if you need to.
$new_file_name = 'New File Name';
// Join the new file name with file extension with (.).
return join( '.', array( $new_file_name, $filetype['ext'] ) );
}
add_filter( 'woocommerce_file_download_filename', 'change_woocommerce_file_download_filename', 10, 2 );
此筛选器挂钩中有两个参数。1: Filename
2: Product ID
然后您可以根据需要更改名称并返回文件名。
注意:新文件名应带有file extension
。
这篇关于WooCommerce重命名数字下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文