自 WooCommerce 版本 2.6 以来,该挂钩woocommerce_available_download_link
包含在myaccount/my-downloads.php
已弃用的模板中(使用的正确模板文件是myaccount/downloads.php
)。
现在由于通过WC_Customer
方法加载下载get_downloadable_products()
,您可以使用woocommerce_customer_get_downloadable_products
此方法中包含的过滤器挂钩。或者也woocommerce_customer_available_downloads
过滤钩。
要从产品名称中删除标签,您可以使用str_replace()
或更好更高效strip_tags()
:
1)。第一种方式- 使用strip_tags()
功能:
add_filter( 'woocommerce_customer_get_downloadable_products', 'remove_span_tags_from_product_name' );
// Or also
// add_filter( 'woocommerce_customer_available_downloads', 'remove_span_tags_from_product_name' );
function remove_span_tags_from_product_name( $downloads ){
// Only on my account downloads section
if ( ! is_wc_endpoint_url('downloads') )
return $downloads;
// Loop though downloads
foreach( $downloads as $key => $download ) {
// remove "span" html tags
$downloads[$key]['product_name'] = strip_tags( $download['product_name'] );
}
return $downloads;
}
2)。另一种方式- 使用str_replace()
功能:
add_filter( 'woocommerce_customer_get_downloadable_products', 'remove_span_tags_from_product_name' );
// Or also
// add_filter( 'woocommerce_customer_available_downloads', 'remove_span_tags_from_product_name' );
function remove_span_tags_from_product_name( $downloads ){
// Only on my account downloads section
if ( ! is_wc_endpoint_url('downloads') )
return $downloads;
// Loop though downloads
foreach( $downloads as $key => $download ) {
// remove "span" html tags
$downloads[$key]['product_name'] = str_replace( array('<span>', '</span>'), array('', ''), $download['product_name'] );
}
return $downloads;
}
代码在您的活动子主题(或活动主题)的functions.php 文件中。任何方式都应该有效。
如果您希望它在任何地方都可以使用(“订单视图”、“已收到订单”、电子邮件通知),请删除:
// Only on my account downloads section
if ( ! is_wc_endpoint_url('downloads') )
return $downloads;