最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Remove span tags from WooCommerce Downloads page

programmeradmin1浏览0评论

Hello i have problem with my woocommerce downloads section in "my account" page - span tags between product name and variation name.

.png

I tried to make a snippet:

add_filter( 'woocommerce_customer_available_downloads', 'remove_span_dl_name', 10, 7);
function remove_span_dl_name( $download ){
return str_replace( '<span> - </span>', ' - ',$download['download_name']);
}

but it removes all downloads altogether.

And this one do nothing:

add_filter( 'woocommerce_available_download_link', 'remove_span_dl_name', 10, 7);
function remove_span_dl_name( $download ){
return str_replace( '<span> - </span>', ' - ',$download['download_name'] );
}

What is my mistake and how can I get rid of these tags?

Hello i have problem with my woocommerce downloads section in "my account" page - span tags between product name and variation name.

https://i.sstatic/TIg0X.png

I tried to make a snippet:

add_filter( 'woocommerce_customer_available_downloads', 'remove_span_dl_name', 10, 7);
function remove_span_dl_name( $download ){
return str_replace( '<span> - </span>', ' - ',$download['download_name']);
}

but it removes all downloads altogether.

And this one do nothing:

add_filter( 'woocommerce_available_download_link', 'remove_span_dl_name', 10, 7);
function remove_span_dl_name( $download ){
return str_replace( '<span> - </span>', ' - ',$download['download_name'] );
}

What is my mistake and how can I get rid of these tags?

Share Improve this question edited Aug 18, 2020 at 23:39 Nate Allen 2,1062 gold badges16 silver badges23 bronze badges asked Aug 9, 2020 at 23:14 Kuroi RyuuKuroi Ryuu 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Remember that str_replace looks for an exact match of the 'needle' (what you are searching for; 'haystack' is the thing you are searching inside). So your code is not finding an exact match.

If you want to do a 'replace everything that might be within the span codes in that hunk of text', then a regex statement might be in order. This is assuming that the 'haystack' you are searching is different each time. (Since I don't read your language, can't tell for sure.

But, assuming that $download['donload_name'] contains the start and stop span tag, and something in the middle, then try to do two str_replace commands: one for the <span> and one for </span>.

And that assumes that there aren't any parameters to the <span>. If there are, a regex might be better idea.

发布评论

评论列表(0)

  1. 暂无评论