我正在使用Woocommerce插件。在可下載的產品中,如何顯示文件名而不是產品名稱?現在可下載的產品在頁面「我的帳戶」中看起來像這樣:如何在WooCommerce中列出每個可下載產品的每個文件名?
title-->file1
title-->file2.
現在我需要將文件的列表顯示到文件名中。例如:在「訂購」頁面中應該是這樣的:
title-->Installer.zip(filename)
title-->Runner.zip(filename)
如何在可下載的產品列表中列出每個文件名?
我現在用的是Woocommerce 2.0.4
<?php
/**
* My Account
*/
global $woocommerce;
?>
<?php $woocommerce->show_messages(); ?>
<p><?php printf(__('Hello, <strong>%s</strong>. From your account dashboard you can view your recent orders, manage your shipping and billing addresses and <a href="%s">change your password</a>.', 'kinetico'), $current_user->display_name, get_permalink(woocommerce_get_page_id('change_password'))); ?></p>
<?php do_action('woocommerce_before_my_account'); ?>
<?php if ($downloads = $woocommerce->customer->get_downloadable_products()) : ?>
<h2><?php _e('Available downloads', 'kinetico'); ?></h2>
<ul class="digital-downloads">
<?php foreach ($downloads as $download) : ?>
<li><?php if (is_numeric($download['downloads_remaining'])) : ?><span class="count"><?php echo $download['downloads_remaining'] . _n(' download Remaining', ' downloads remaining', $download['downloads_remaining'], 'kinetico'); ?></span><?php endif; ?> <a href="<?php echo esc_url($download['download_url']); ?>"><?php echo $download['download_name']; ?></a></li>
<?php echo $download['download_name']; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php add_filter('woocommerce_available_download_link', 'filter_wc_downloads_so_16142748', 10, 2);
function filter_wc_downloads_so_16142748($link, $download)
{
// Create a WC_Order object and get the file URLs for this product
$order = new WC_Order($download['order_id']);
$download_file_urls = $order->get_downloadable_file_urls(
$download['product_id'],
null,
$download['download_id']
);
// Check each download URL and compare with the current URL
// $key contains the real file URL and $value is the encoded URL
foreach($download_file_urls as $key => $value)
{
if($value == $download['download_url'])
{
$url_parts = explode('/', parse_url($key, PHP_URL_PATH));
$file_name = end($url_parts);
$link = '<a href="'
. esc_url($download['download_url'])
. '">'
. $download['download_name']
. '</a> <small>('
. $file_name
. ')</small>';
}
}
return $link;
}?>
<h2><?php _e('Recent Orders', 'kinetico'); ?></h2>
<?php woocommerce_get_template('myaccount/my-orders.php', array('recent_orders' => $recent_orders)); ?>
<h2><?php _e('My Address', 'kinetico'); ?></h2>
<p><?php _e('The following addresses will be used on the checkout page by default.', 'kinetico'); ?></p>
<?php woocommerce_get_template('myaccount/my-address.php'); ?>
<?php
do_action('woocommerce_after_my_account');
add_filter('woocommerce_available_download_link', 'filter_wc_downloads_so_16142748', 10, 2);
哦,我看到了錯誤。我的代碼並不意味着在主題模板中。製作一個小插件,參考[本答覆](http://wordpress.stackexchange.com/a/72183/12615)瞭解如何繼續。也許你可以清理問題,模板不相關。 – brasofilo 2013-05-15 05:58:48